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!

null check on field doesn't quit if statement 2

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
0
0
GB
Hi,

Am I correct in saying that the following will still error because access doesn't quit an if statement the minute the evaluation fails / meets the criteria

Code:
Dim myDate As Date

If Nz(myDate,"") = "" Or myDate < now() Then
 'do something
End If

I'm getting invalid use of null error, yet the first test should match and so not bother with the next test.

Why would an if statement test every expression when it has already made its match?

Thanks,
1DMF

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
Yes because of the OR both conditions get evaluated. I believe if it is an AND and the first condition is not met then it short circuits. If it is separated by else it would short circuit.
With dates I would not check it like that, more complete to use
If isdate(myDate). Then it checks for null, "", " ", or anything else not a date. Even things that look like a date but are not.
 
is that unique to VBA?

I'm sure Perl short circuits on first match?

So I either have to nest with if/else or give it a default...
Code:
If Not IsDate(myDate) Or Nz(myDate,"01/01/1901") < now() Then
 'do something
End If

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
VB(a)'s logical operators And, Or, Nor, Xor etc are bitwise operators rather than true booleans. As a result they need to evaluate their operands before being able to do a comparison - hence no short-circuiting. Effectively (A or B) is an single operation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top