Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing Null

Status
Not open for further replies.

Chesterex1

Vendor
Mar 31, 2003
34
0
0
CA
I have Null values that I want to skip if the field is Null

I have tried the following to no avail:

If Recordset!Fieldname Is Null then ...

..aslo..

If Recordset!Fieldname = Null then ...

Any thoughts?
Thanks
Tim
 
The proper check for null is:

If IsNull(Recordset!Fieldname) Then

And just to show how to check for something not null...

If Not IsNull(Recordset!Fieldname) Then


****************************
Only two things are infinite, the universe and human stupidity,
and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III
MCSA, CNA, MCP, Network+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
I have a question about the checking of null values...

Is it better to use the above format, or this one:
Code:
if IsNull(Recordset!Fieldname) = True then
...
if IsNull(RecordSet!Fieldname) = False then
...

I use this most of the time, because it's easier for me to think that way.. but would leaving out the =true/false and using the NOT for false be better?

GComyn
 
When using IsNull(whatever), you don't have to include the true....but you can use it instead of Not IsNull(whatever) as I previously demonstrated....I was taught to use Not IsNull() so that is what I use....

****************************
Only two things are infinite, the universe and human stupidity,
and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III
MCSA, CNA, MCP, Network+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
Either one works, but mstrmage's syntax is more concise. I'm far from an expert on this stuff, but your syntax causes 2 expressions to be evaluated. The IsNull function itself returns either true or false; then you're testing whether the boolean returned by IsNull is true or false, i.e. If True = True Then... The net result is the same, and the performance hit for evaluating 2 expressions instead of one is measured in nanoseconds, so in the long run it probably doesn't really matter. For me it's more an issue of staying with good coding practices to avoid problems, and being as concise as possible to get maximum performance.

Also, from the MS Access help files re: your original question:

Important Use the IsNull function to determine whether an expression contains a Null value. Expressions that you might expect to evaluate to True under some circumstances, such as If Var = Null and If Var <> Null, are always False. This is because any expression containing a Null is itself Null and, therefore, False.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top