Results 1 to 8 of 8
  1. #1
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581

    DLOOKUP with multiple criteria


    I tried to look at previous postings, but I couldn't figure it out. I have some text boxes that I'm trying to get data from a query. I need [RaceID] = 1 and [ContactDisp] = 3. This is what I'm trying to use, but get an error:
    =DLookUp("[TotalDisp]","qryStatDispo3a","[RaceID] =" & 1 & "AND [ContactDisp] ='" & 3 & "'")

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    If those are fixed values the no need for all the concatenation.

    =DLookUp("[TotalDisp]","qryStatDispo3a","[RaceID] =1 AND [ContactDisp] ='3'")

    That also assumes ContactDisplay is Text?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Just need a space in front of AND. But don't need concatenation with static parameters.

    =DLookUp("[TotalDisp]","qryStatDispo3a","[RaceID] = 1 AND [ContactDisp] = '3'")

    ContactDisp is a text data type? If it's a number, remove apostrophe delimiters.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    RaceID and ContactDisp are both coming from the query.

  5. #5
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    RaceID is a number. ContactDisp is calculated by the query.

  6. #6
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I must be tired. I was using the wrong field.
    =DLookUp("TotalDisp","qryStatDispo3a","RaceID = 1 and ContactDispositionID = 3")

    This worked.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    For when you do actually need to concatenate.

    I tend to put the criteria into a string variable for domain functions if not a single simple criteria.
    Then I can debug.print them to see if I have the syntax correct.
    Then when correct, I can use that in the function.
    Plus, if you cannot see the error, you can copy and paste here or eslewhere, so someone can point out the error.?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I appreciate the help. Thank you.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Dlookup with multiple criteria
    By jeffhanner10@gmail.com in forum Programming
    Replies: 2
    Last Post: 02-05-2020, 02:07 PM
  2. DLookup with multiple criteria
    By amai in forum Access
    Replies: 2
    Last Post: 12-20-2015, 02:10 PM
  3. Help with multiple criteria DLookup
    By jtm013 in forum Programming
    Replies: 7
    Last Post: 04-23-2015, 03:16 PM
  4. DLookup with multiple criteria
    By RunTime91 in forum Access
    Replies: 4
    Last Post: 02-08-2015, 08:28 PM
  5. Using DLookup with multiple criteria
    By halt4814 in forum Access
    Replies: 2
    Last Post: 04-08-2013, 12:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums