Invalid use of Null Error

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
 
G

Gerald Stanley

Instead of TypeCrit = Null, use IsNull(TypeCrit)

Hope This Helps
Gerald Stanley MCSD
 
A

Allen Browne

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top