Better syntax?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MLH

    #1

    Better syntax?

    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.
  • Rick Brandt

    #2
    Re: Better syntax?

    MLH wrote:[color=blue]
    > 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.[/color]

    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


    Comment

    • paii, Ron

      #3
      Re: Better syntax?


      "MLH" <CRCI@NorthStat e.net> wrote in message
      news:115q62dcn3 ggut9vsdsuqa30v j6a7t30cb@4ax.c om...[color=blue]
      > 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.[/color]

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

      Assuming [YR] = 0 is not acceptable ,


      Comment

      • MLH

        #4
        Re: Better syntax?

        On Fri, 19 May 2006 02:39:14 GMT, "Rick Brandt"
        <rickbrandt2@ho tmail.com> wrote:
        [color=blue]
        >MLH wrote:[color=green]
        >> 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.[/color]
        >
        >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.[/color]
        =============== =============== =============
        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


        Comment

        Working...