Invalid use of Null Error

  • Thread starter Thread starter Fatz
  • Start date Start date
F

Fatz

I have a form with a button that runs the following code when clicked:

Private Sub Command3_Click()

Dim TypeCrit As String
TypeCrit = DLookup("[Type]", "tblMainTable", "[Case#]=" & Me.Case)
If TypeCrit = Null Or TypeCrit = "" Then
MsgBox "Enter Cert Number First"
ElseIf TypeCrit = "X99" Then
DoCmd.OpenForm "frmX99"
Else
DoCmd.OpenForm "frmINV"
End If

DoCmd.Close acForm, Me.Name

End Sub

Can anyone tell me why I am getting a "Invalid use of Null" error
here?? Can you also provide me with an example of how to fix it??

Thanks for your help!!

-Chris
 
Instead of TypeCrit = Null, use IsNull(TypeCrit)

Hope This Helps
Gerald Stanley MCSD
 
DLookup() can return Null, but a string variable cannot hold a null.
Use a Variant instead.

Also, replace the line:
If TypeCrit = Null ...
with:
If IsNull(TypeCrit) ...
Nothing is ever equal to Null.

Both these issues are explained in article:
Common errors with Null
at:
http://allenbrowne.com/casu-12.html
 
Back
Top