IsNull Not Working

  • Thread starter Thread starter bw
  • Start date Start date
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
 
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
 
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
 
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
 
Back
Top