Results 1 to 8 of 8

Multiple criteria in DLookup

  1. #1
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    370

    Multiple criteria in DLookup

    Are you able to have 2 criterias in a DLookup statement? Here's the vital info:
    Expr: OnHandQty
    table name: ICPartWarehouse
    criteria: FKICPart = me.FKICPart and WarehouseNumber = 3
    both FKICPart & WarehouseNumber are fields within the table

    Here's what I have so far:
    =DLookUp("OnHandQty","ICPartWarehouse",????)

    Thanks for your assistance!!

  2. #2
    June7's Avatar
    June7 is offline Moderator
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    31,313
    You can have has many criteria as you want, as far as the ControlSource string length limit will allow. If FKICPart is a number datatype, remove the apostrophe delimiters. The Me qualifier is VBA, can't use in Access.
    =DLookUp("OnHandQty","ICPartWarehouse", "FKICPart ='" & [FKICPart] & "' And WarehouseNumber = 3")
    To provide db: Make copy, remove confidential data, run compact & repair, zip w/Windows Compression if over 500KB (2MB zip allowed), attach to post. Attachment Manager is below the Advanced post editor window.
    If suggestion in this post resolves your issue, please use the Thread Tools and mark the thread as Solved!

    Debug!Debug!Debug! http://www.cpearson.com/excel/debug.htm

  3. #3
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    370
    I receive an error. Both FKICPart and WarehouseNumber are fields within the table, and both are numeric. In the search criteria I need FKICPart = text190 and WarehouseNumber = 3.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    10,960
    Try:
    =DLookUp("OnHandQty","ICPartWarehouse", "FKICPart = '" & Me.text190 & "' And WarehouseNumber = 3")
    (RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 Pro - acXP, ac07, ac10, ac13
    If your issue is resolved...go ahead and use the Thread Tools at the top of the thread and mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  5. #5
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    370
    Thanks for the assistance. I've been testing different things, and nothing has worked yet. I pasted your suggestion, and I had to change WarehouseNumber to WarehouseNo. Within the field I'm receiving #Name? If I trouble shoot with only using 1 criteria, it works properly. When I add the second criteria, I receive the error message. When I only use 1 criteria, I'm manipulating the data so I only have 1 match.

  6. #6
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    370
    I should also write that text190 is a Dlookup. Here's what is in text190, =DLookUp("SKICPart","ICPart","ID ='" & [ISBNBW] & "'"). Within the dlookup that I'm having the problem, all fields are numeric. In the Dlookup that is in text190, SKICPart is numeric, and ID & ISBNBW are text.

  7. #7
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    370
    After spending many hours on this with no solution, I decided to write VBA behind the form. It works great. Maybe there is a problem within Access 2010 an multiple criteria in a DLookup.

  8. #8
    June7's Avatar
    June7 is offline Moderator
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    31,313
    No, multiple criteria works fine. However, my DLookup used a field in the form's recordset as criteria. Never tried a DLookup that used the results of another DLookup. Did not test but problem must be with that.
    To provide db: Make copy, remove confidential data, run compact & repair, zip w/Windows Compression if over 500KB (2MB zip allowed), attach to post. Attachment Manager is below the Advanced post editor window.
    If suggestion in this post resolves your issue, please use the Thread Tools and mark the thread as Solved!

    Debug!Debug!Debug! http://www.cpearson.com/excel/debug.htm

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

Similar Threads

  1. Replies: 1
    Last Post: 06-16-2011, 11:59 PM
  2. Search with multiple criteria
    By injanib in forum Forms
    Replies: 1
    Last Post: 01-16-2011, 09:51 PM
  3. Multiple Criteria in a string
    By cksm4 in forum Programming
    Replies: 3
    Last Post: 08-04-2010, 10:54 AM
  4. Dlookup to match two criteria and return value
    By randolphoralph in forum Programming
    Replies: 20
    Last Post: 05-20-2010, 11:27 AM
  5. Multiple criteria query
    By DJ-Specter in forum Queries
    Replies: 1
    Last Post: 09-23-2009, 03: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
  •  
Tech Forums: Microsoft Office Forums