Results 1 to 7 of 7
  1. #1
    Ganymede is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Dec 2011
    Posts
    116

    Dlookup in Query Field with multiple criteria


    I have a query titled "Query1" that has the following fields: Issue, Engagement and Year. In a separate field in Query1, I want to run a dlookup against a different query titled "Query2," which also contains fields titled Issue, Engagement, year, plus an additional field titled "CaseNo." I want the result of the dlookup to find the CaseNo from Query2 that is in the same row as the Issue, Engagement and Year in Query1. There are no repeats in Query 2. That is, there is no row in query 2 where the same combination of Issue, Engagement and Year are repeated.

    Here is the dlookup formula that I created. Note that all of the criteria fields are strings. So I used the string snytax.

    Code:
    DLookUp("[CaseNo]","[Query2]","[Issue] = '" & [Issue] & "'" And "[Engagement] = '" & [Engagement] & "'" And "[Year] ='" & [Year] & "'")
    For some reason the result I get is the CaseNo in the first Line in Query 2 where the Issue matches. It's as if the Dlookup is searching for the first row where Issue matches and stopping there, instead of then searching for where Engagement and Year also match. Am I going about this the wrong way? Is there another way to acheive the same outcome? I'm open to any suggestion.

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Your syntax is wrong, please try this:
    Code:
    Case_No:DLookUp("[CaseNo]","[Query2]","[Issue] = '" & [Issue] & "' And [Engagement] = '" & [Engagement] & "' And [Year] ='" & [Year] & "'")
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Domain aggregate functions can slow performance of query.

    Why don't you build query that JOINs on those 3 pairs of common fields?
    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
    Ganymede is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Dec 2011
    Posts
    116
    Quote Originally Posted by Gicu View Post
    Your syntax is wrong, please try this:
    Code:
    Case_No:DLookUp("[CaseNo]","[Query2]","[Issue] = '" & [Issue] & "' And [Engagement] = '" & [Engagement] & "' And [Year] ='" & [Year] & "'")
    Cheers,
    Thank you! I couldn't quite get this solution to work. Perhaps I was mistaken in my assumption that all of those fields are string. But I did find a workaround. I basically created several layered queries to get the result I was after.

  5. #5
    Ganymede is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Dec 2011
    Posts
    116
    Quote Originally Posted by June7 View Post
    Domain aggregate functions can slow performance of query.

    Why don't you build query that JOINs on those 3 pairs of common fields?
    That's what I ended up doing. The difficulty is that those fields were spread among multiple tables. But I finally figured out how to do it. Thanks!

  6. #6
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    IIRC, sometimes domain functions don't like having the object name enclosed in [brackets] when not needed. They are only needed when the field/domain contains spaces, which should never be the case. Same with using reserved words for object names, like Year.

    http://www.allenbrowne.com/AppIssueBadWord.html
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    AFAIK, domain aggregate function never has issue with included brackets, needed or not. What is odd is that the domain argument DOES NOT require brackets even if there are spaces/special characters in table/query name.
    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.

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

Similar Threads

  1. Replies: 9
    Last Post: 02-11-2025, 03:54 AM
  2. Replies: 5
    Last Post: 01-30-2018, 01:16 PM
  3. Replies: 2
    Last Post: 09-11-2015, 12:42 PM
  4. Replies: 15
    Last Post: 07-09-2015, 01:39 AM
  5. Multiple criteria in DLookup
    By crowegreg in forum Forms
    Replies: 7
    Last Post: 06-22-2011, 01:47 AM

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