By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,780 Members | 1,549 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,780 IT Pros & Developers. It's quick & easy.

Better syntax?

P: n/a
MLH
If Not IsNull(DLookup("[YR]", "tblCars", "[VID]=GetCurrVID()")) Then

If DLookup("[YR]", "tblCars", "[VID]=GetCurrVID()") Then

Of the above 2 syntax variations, is the 2nd unacceptable? I use the
former because I seem to remember suggestions in this forum that
discouraged the latter. But I tire of it. To me, the latter is more
readily understood because there's no double negative to deal with.
May 19 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
MLH wrote:
If Not IsNull(DLookup("[YR]", "tblCars", "[VID]=GetCurrVID()")) Then

If DLookup("[YR]", "tblCars", "[VID]=GetCurrVID()") Then

Of the above 2 syntax variations, is the 2nd unacceptable? I use the
former because I seem to remember suggestions in this forum that
discouraged the latter. But I tire of it. To me, the latter is more
readily understood because there's no double negative to deal with.


If the value of [YR] returned is zero or null then the expression will not work
as expected.

If the criteria finds no rows you will get null back (not false).

Using DCount() instead of DLookup() would solve both of those problems, but
might take a few more clicks to resolve.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
May 19 '06 #2

P: n/a

"MLH" <CR**@NorthState.net> wrote in message
news:11********************************@4ax.com...
If Not IsNull(DLookup("[YR]", "tblCars", "[VID]=GetCurrVID()")) Then

If DLookup("[YR]", "tblCars", "[VID]=GetCurrVID()") Then

Of the above 2 syntax variations, is the 2nd unacceptable? I use the
former because I seem to remember suggestions in this forum that
discouraged the latter. But I tire of it. To me, the latter is more
readily understood because there's no double negative to deal with.


If NZ(DLookup("[YR]", "tblCars", "[VID]=GetCurrVID()"), 0) <> 0 Then

Assuming [YR] = 0 is not acceptable ,
May 19 '06 #3

P: n/a
MLH
On Fri, 19 May 2006 02:39:14 GMT, "Rick Brandt"
<ri*********@hotmail.com> wrote:
MLH wrote:
If Not IsNull(DLookup("[YR]", "tblCars", "[VID]=GetCurrVID()")) Then

If DLookup("[YR]", "tblCars", "[VID]=GetCurrVID()") Then

Of the above 2 syntax variations, is the 2nd unacceptable? I use the
former because I seem to remember suggestions in this forum that
discouraged the latter. But I tire of it. To me, the latter is more
readily understood because there's no double negative to deal with.


If the value of [YR] returned is zero or null then the expression will not work
as expected.

If the criteria finds no rows you will get null back (not false).

Using DCount() instead of DLookup() would solve both of those problems, but
might take a few more clicks to resolve.

===========================================
I see your point. I can rid myself of the dbl-neg situation
easily enough by reversing the Do This or Do That. But
I think I like your DCount suggestion better.

If [double-negative condition] Then
Do THIS if true
Else
Do THAT if false
Endif
If [straight-forward condition w/ NO dbl-neg] Then
Do THAT if true
Else
Do THIS if false
Endif
May 19 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.