WHERE isnull in vba

icemonster

Registered User.
Local time
Today, 17:10
Joined
Jan 30, 2010
Messages
502
so am trying to figure out the proper way to write this:

strWheresSql1 = "WHERE qry1.field1 = Is null "

seems not to be working?
 
I am not sure when you would need to use such a criteria.

If a field has nothing in it, it would surely be picked up with
  • "WHERE qry1.field1 = """"".
Does a checkbox's 3rd state qualify as null? if so i would have thought
  • "WHERE ((qry1.field1 <> TRUE) AND (qry1.field1 <> FALSE)) would do that.
OR (just thought of this:eek:)
  • "WHERE IsNull(Field1)"
 
Last edited:
just remove the equals:

strWheresSql1 = "WHERE qry1.field1 Is null "
 
Isskint,
"" which is a zero-length-string (ZLS) is NOT the same as a null. So, "WHERE qry1.field1 = """"" will not find null values.
 
Thanks Pat, I sort of 'overlooked' that one:eek:.... (memo to self think b4 posting:p)
 
It is important to realise that the comparator keyword for Null is "Is".

I expect Is is used because Null is actually more like an object (an empty one) than a variable and is thus treated more like and object than a variable.
In VBA we write:
Code:
If SomeObject Is Nothing Then
Rather Than:
Code:
If SomeObject = Nothing Then

Indeed Null doesn't actually equal anything.
The following expressions both return Null (which will be interpreted as False).
(Null = Null)
(Null <> Null)

So we use:
IsNull(Null) to get a True output.

BTW This expression returns False so Null and Nothing are not the same.
IsNull(Nothing)
 

Users who are viewing this thread

Back
Top Bottom