IsNull Not Working

B

bw

Can someone explain what's wrong with the following. A branch to the
Message Box is NOT taken, and the value of X is null.
Thanks,
Bernie

Dim X As Variant
X = Null
If IsNull(X) = DLookup("BankName", "qryLookup", "BankName = '" &
[BankName] & "'") Then
MsgBox "X IS NULL"
Else
If Not IsNull(X) Then
MsgBox "X IS NOT NULL"
End If
End If
 
T

Ted Allen

Hi Berni,

Your If statement is not just checking to see if x is null, it is checking
to see if the result of IsNull(X) = DLookup...

So, if x is null, the left part of the expression would be true and the If
statement would become:

If True = DLookup...

So, if the DLookup returns true (which isn't likely since it is looking up a
value in a bank name field) the expression will be true, otherwise it will be
false. For instance, say the Dlookup returns "Bank of America", your If
statement becomes:

If True = "Bank of America"

which will of course be false.

If you want to check to see if x is null, change the If expression to:

If IsNull(x) Then...

HTH, Ted Allen
 
J

John Horner

bw <[email protected]> said:
Can someone explain what's wrong with the following. A branch to the
Message Box is NOT taken, and the value of X is null.
Thanks,
Bernie

Dim X As Variant
X = Null
If IsNull(X) = DLookup("BankName", "qryLookup", "BankName = '" &
[BankName] & "'") Then
MsgBox "X IS NULL"
Else
If Not IsNull(X) Then
MsgBox "X IS NOT NULL"
End If
End If
Try
Dim X As Variant
X = DLookup("BankName", "qryLookup", "BankName = '" &
[BankName] & "'")

If IsNull(X) Then
MsgBox "X IS NULL"
Else

MsgBox "X =" & X

End If
 
B

bw

Ted and John,

I changed my expression as you suggested, and it works fine now. The
explanation was very helpful.
Thanks for your help,
Bernie
 

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