Dlookup with 2 criteria

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MSeda
    Recognized Expert New Member
    • Sep 2006
    • 159

    Dlookup with 2 criteria

    I have a loop that is controlled by a Dlookup statement with two criteria. Both criteria fields are checkboxes. I have tried an assortment of quotation marks in the criteria section and cannot get the Dlookup to run. My statement looks like this (I have removed the extraneous quotes since they are not working anyway):

    Do Until IsNull(DLookup( "[PPO Part#]", "Quoted Parts Table", "[PPO Quote Acc] = Yes And [PPO Order Parts] = Yes"))

    I've never quite understood the logic of the quotation marks in the criteria statement but it usually works after several tries, this is the first time I,ve used Dlookup with 2 criteria. Any help will be appreciated
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32668

    #2
    The amended code should work for you.

    Code:
    Do Until IsNull(DLookup( _
       Expr:="[PPO Part#]", _
       Domain:="Quoted Parts Table", _
       Criteria:="(([PPO Quote Acc]) And ([PPO Order Parts]))"))
    I've assumed from your code that [PPO Quote Acc] and [PPO Order Parts] fields are both of type Boolean so will not need to be compared to Yes.
    If they are text fields and you need to compare against the text "Yes" then that is different and will need a code change.

    Comment

    • MMcCarthy
      Recognized Expert MVP
      • Aug 2006
      • 14387

      #3
      Two things:

      Table and field names cannot contain blank spaces so they need to be inclosed in square brackets to show what they are.

      Yes is text and all text has to be surrounded by single or double quotation marks (single inside a query).

      therefore

      Do Until IsNull(DLookup( "[PPO Part#]", "[Quoted Parts Table]", "[PPO Quote Acc] = 'Yes' And [PPO Order Parts] = 'Yes'"))

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32668

        #4
        I missed out on the '[]' for the table name.

        Code:
        Do Until IsNull(DLookup( _
           Expr:="[PPO Part#]", _
           Domain:="[Quoted Parts Table]", _
           Criteria:="(([PPO Quote Acc]) And ([PPO Order Parts]))"))
        However, Yes can be a string but can also be an alternative for True - a predefined constant within VBA.
        If you want Yes, the code above is ok, if you want "Yes" then change the last line to :-
        Code:
           Criteria:="(([PPO Quote Acc] = 'Yes') And ([PPO Order Parts] = 'Yes'))"))
        as shown by MMcCarthy above.

        Comment

        Working...