Results 1 to 13 of 13
  1. #1
    nbrock2002 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    8

    Angry Dlookup w/multiple criterias on a subform


    Hello, I've hunted and have tested multiple possible solutions without a working one and I need help. I'm trying to use Dlookup in the Expression Builder on subform TimesheetReviewByDateSubform to show PiecesPerHr from EmployeeProductionQuery. The form needs to be edible and the info I'm trying to reference would prevent that so Dlookup has been my solution. If there is another way I'm open to that as well. Here is the formula as it stands now.

    =DLookUp("[PiecesPerHr]","EmployeeProductionQuery","[EmployeeProductionQuery].[CustomerDate]=" & [Forms].[TimesheetReviewByDate].[TimesheetReviewByDateSubform].[Form].[CustomerDate] & " And [EmployeeProductionQuery].[EmployeeNumber] =" & [Forms].[TimesheetReviewByDate].[TimesheetReviewByDateSubform].[Form].[EmployeeNumber])

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    Not clear what your question is.

    The alternative is to use vba to assign your dlookup value to the control, and your control needs to be bound to the appropriate field, not the dlookup. code might be something like

    PiecesPerHr=DLookUp("[PiecesPerHr]","EmployeeProductionQuery","[EmployeeProductionQuery].[CustomerDate]=" & [Forms].[TimesheetReviewByDate].[TimesheetReviewByDateSubform].[Form].[CustomerDate] & " And [EmployeeProductionQuery].[EmployeeNumber] =" & [Forms].[TimesheetReviewByDate].[TimesheetReviewByDateSubform].[Form].[EmployeeNumber])

    you don't need to refer to the query each time, so to simplify

    PiecesPerHr=DLookUp("[PiecesPerHr]","EmployeeProductionQuery","[CustomerDate]=" & [Forms].[TimesheetReviewByDate].[TimesheetReviewByDateSubform].[Form].[CustomerDate] & " And [EmployeeNumber] =" & [Forms].[TimesheetReviewByDate].[TimesheetReviewByDateSubform].[Form].[EmployeeNumber])

    and if your code is in the subform then you can simplify further

    PiecesPerHr=DLookUp("[PiecesPerHr]","EmployeeProductionQuery","[CustomerDate]=" & CustomerDate & " And [EmployeeNumber] =" & EmployeeNumber)

    or if in the main form

    PiecesPerHr=DLookUp("[PiecesPerHr]","EmployeeProductionQuery","[CustomerDate]=" & TimesheetReviewByDateSubform.Form.CustomerDate & " And [EmployeeNumber] =" & TimesheetReviewByDateSubform.Form.EmployeeNumber)

    as to which event you run the code on - that depends on what your subform looks like. On the basis it is a single form, then the subform current event would appear to be appropriate. Or perhaps the after update event of the employeenumber control?



  3. #3
    nbrock2002 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    8
    I'm still learning but I was using the formula in a Text Box itself. That does not sound like what your suggesting. My subform is a continuous form and my main form is Single.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Note the delimiters required for date fields (& text if appropriate):

    http://www.theaccessweb.com/general/gen0018.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    nbrock2002 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    8
    It must have to do with my fields and formats not the formula itself. I get an error #Name?. Will need do some digging. Thanks for the help.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Did you add delimiters for what looks like a date/time field?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    nbrock2002 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    8
    I did try adding delimiters however Its not really a date. It is a combo of a CustomerNumber and Date which could be part of my problem. I did try to simplify the formula to focus on one criteria at a time but that would not work for me either. I tried both formulas below and am still getting #Name?.

    =DLookUp("[PiecesPerHr]","EmployeeProductionQuery","[EmployeeNumber] =" & [Forms].[TimesheetReviewByDate].[TimesheetReviewByDateSubform].[Form].[EmployeeNumber]) &

    =DLookUp("[PiecesPerHr]","EmployeeProductionQuery","[EmployeeNumber] ='" & [Forms].[TimesheetReviewByDate].[TimesheetReviewByDateSubform].[Form].[EmployeeNumber] & "'")

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can you attach the db here, with test data?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    nbrock2002 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    8
    Unfortunately I am not able to, sorry. I know that makes it very tough to help me at this point.

  10. #10
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    I suspect that we have to do with a MVF.

    @nbrock2002
    Put the expression below in an unbound textbox in the subform and let us know what you see:
    Code:
    =[CustomerDate] & " - " & [EmployeeNumber]
    Or that expression in an unbound textbox in the main form:
    Code:
    =[TimesheetReviewByDateSubform]![CustomerDate] & " - " & [TimesheetReviewByDateSubform]![EmployeeNumber]

  11. #11
    nbrock2002 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    8
    If I put the first code in the subform I do still get an error #Name?.

  12. #12
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Do you use multivalued fields? (I have never used them)

    Give a try to these expressions below:
    =[CustomerDate]
    =[EmployeeNumber]
    =[CustomerDate].[Value]
    =[EmployeeNumber].[Value]

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    If you can't provide copy of database with confidential info removed, we probably won't be able to help.
    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. Multiple criterias in Dlookup function
    By maxchang9 in forum Queries
    Replies: 9
    Last Post: 01-25-2019, 07:01 PM
  2. Replies: 3
    Last Post: 08-04-2016, 01:01 PM
  3. How to search for multiple criterias using comboBox?
    By AccessPractice in forum Programming
    Replies: 2
    Last Post: 04-29-2016, 03:59 AM
  4. Replies: 19
    Last Post: 08-01-2013, 10:47 AM
  5. Update Multiple fields according multiple criterias
    By denis.m in forum Programming
    Replies: 1
    Last Post: 02-21-2011, 11:03 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