Results 1 to 12 of 12
  1. #1
    jtolsma is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    9

    Unhappy Dlookup with multiple criteria including dates

    I am stuck on the following code. I keep trying to make changes to it and continue to get errors. The code listed below gives me a type mismatch error. (I have seen syntex errors also)
    Any suggestions on what I am doing wrong? (The Code is text, EmpNum is a number and the other is a date. I have checked the tables this relates to and the formatting matches)



    Code1 = DLookup("[Code]", "Attendance Data", "[EmpNum]= " & Forms![Warning Data]!EmpNum & """" And "[AttendanceDate]= #" & Forms![Warning Data]![AttendanceDate1] & "#")

    Thanks for all of your help
    Jessica

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    See if the multi-criteria at the end of this helps:

    DLookup Usage Samples

    FYI, the data type of Code is irrelevant. You've got a bunch of extraneous quotes there.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jtolsma is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    9
    I have referred to that link a number of times, even when trying to put this command together and still can't seem to get it right. You mentioned that I have a bunch of extraneous quotes so I tried some modifications, listed below, but they still aren't correct.
    Code1 = DLookup("[Code]", "Attendance Data", "[EmpNum]= " & Forms![Warning Data]!EmpNum And "[AttendanceDate]= #" & Forms![Warning Data]![AttendanceDate1] & "#") RESULT - Error 13
    Code1 = DLookup("[Code]", "Attendance Data", "[EmpNum]= " & Forms![Warning Data]!EmpNum And "[AttendanceDate]= #" & Forms![Warning Data]![AttendanceDate1]) RESULT - Error 13
    Code1 = DLookup("[Code]", "Attendance Data", "[EmpNum]= " & Forms![Warning Data]!EmpNum & """" And "[AttendanceDate]= #" & Forms![Warning Data]![AttendanceDate1]) RESULT - Error 13
    Code1 = DLookup("[Code]", "Attendance Data", "[EmpNum]= " & Forms![Warning Data]!EmpNum & "" And "[AttendanceDate]= #" & Forms![Warning Data]![AttendanceDate1]) RESULT - Error 13
    Code1 = DLookup("[Code]", "Attendance Data", "[EmpNum]= " & Forms![Warning Data]!EmpNum & "" And "[AttendanceDate]= #" & Forms![Warning Data]![AttendanceDate1] & "#") RESULT - Error 13

    I feel like I am missing something simple, which is why I am looking for an extra set of eyes for help.
    Thanks
    Jessica

  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
    Always too many or not enough. Try this:

    DLookup("[Code]", "Attendance Data", "[EmpNum]= " & Forms![Warning Data]!EmpNum & " And [AttendanceDate]= #" & Forms![Warning Data]![AttendanceDate1] & "#")

    which assumes EmpNum has a numeric data type.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    jtolsma is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    9
    I tried that and I get a Syntax error

  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
    Can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    jtolsma is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    9
    I'm sorry, I am not sure what you are asking.

  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
    I'm asking if you can attach your database to a post here so I can debug what's going wrong with it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    jtolsma is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    9
    Sorry...I am having a brain dead day
    I had to take alot of data out to make it small enough, but I think this contains everything you need.

    Database3.accdb

    I hope I attached that correctly
    Thanks

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sorry, I was just correcting the DLookup. You still need the "Code1 = " part, or whatever it is you want to do with the value.

    By the way, your data is not normalized, with the repeating fields (code1, code2, etc). Typically that should be in a related table as records rather than repeating fields.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    jtolsma is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    9
    Thank you so very much. You solved everything!
    I am not thrilled with the way I have to set this database (I only sent you a very small portion of it), but I have to do it in a way my boss can understand.
    Thank you again

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help. That design will be difficult to work with I'm guessing. Thank goodness I work for a boss that doesn't worry about "how", just that the app does what it's supposed to do. If the boss doesn't understand proper design, they shouldn't be involved in it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Query Criteria with Multiple Dates
    By Jojojo in forum Queries
    Replies: 3
    Last Post: 10-08-2011, 05:07 PM
  2. Replies: 2
    Last Post: 08-04-2011, 08:07 AM
  3. Replies: 3
    Last Post: 07-05-2011, 02:25 PM
  4. Multiple criteria in DLookup
    By crowegreg in forum Forms
    Replies: 7
    Last Post: 06-22-2011, 01:47 AM
  5. Replies: 1
    Last Post: 06-17-2011, 12:59 AM

Tags for this Thread

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