Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    sseniour is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2019
    Posts
    10

    Lookup Question

    Have a query that has short time field. trying to use that field to lookup prod mins in a table, but I can't get syntax correct.

    Example: Query field has 12:36. Want to look up 12:36 in the below table and return 303. TIA



  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    not enough information to suggest a solution for your problem. Please clarify

    1. is 12:36 a datetime field or a text field? - ignore (I can't read!)
    2. what is the 'below table'. Also provide some example data from that table
    3. provide an example of the syntax you have tried - plus any error messages
    4. where are you doing the lookup? in the query? in a form? in a report?

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    Use TimeValue()

    No table below.
    You need to use the attach option on this site.
    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

  4. #4
    sseniour is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2019
    Posts
    10
    12:36 is a date/time field in query1. In query2, trying to use that time and "lookup" prod mins in a table that looks like this

    Time Prod Mins
    12:33:00 300
    12:34:00 301
    12:35:00 302
    12:36:00 303
    12:37:00 304
    etc...

    so ending result would be 303

    thanks

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    Use a join? or as I have already said try Timevalue()
    If both are short time then a join should work, else a DlookUp()
    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

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Office 365
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    If you want to extract just the time from a date/time variable, this will do it.

    format(timevalue(now),"hh:nn")
    results in 09:49

  7. #7
    sseniour is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2019
    Posts
    10
    This is what I'm using to try and lookup

    Current Prod Min: DLookUp("Prod Mins","Production Minutes","New 1st unload Time=#" & "OT 00 Time" & "#")

    Table = "Production Minutes"

    Time Prod Mins

    12:33:00 300
    12:34:00 301
    12:35:00 302
    12:36:00 303
    12:37:00 304

    New 1st unload Time = 12:36

    So result of formula should be 303.

    Thanks!

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    Quote Originally Posted by davegri View Post
    If you want to extract just the time from a date/time variable, this will do it.

    format(timevalue(now),"hh:nn")
    results in 09:49
    That produces a string though?
    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

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    If you must have spaces in field names (stupid in my opinion, much more hard work) then you need to enclose within []
    Put the criteria into in string variable and debug.print it until you get it correct.

    Code:
    ? dlookup("PressureID","tblPressure","Timevalue(PressureDateTime)= Timevalue('13:15:07')")
     937
    Edit: If that is actually your table, you could just do the math?, but that would still involve a lookup unless you know the starting value is always the same?
    Attached Thumbnails Attached Thumbnails Screenshot 2025-08-28 175224.png  
    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

  10. #10
    sseniour is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2019
    Posts
    10
    Click image for larger version. 

Name:	pic3.png 
Views:	26 
Size:	100.8 KB 
ID:	53228

    Not sure where to go from here.... the name that is referenced, "Current 1st Unload Time" is a field in the query Q_FirstUnloadTimes3
    Attached Thumbnails Attached Thumbnails 2025-08-28_13-44-45.png   2025-08-28_13-49-52.png  

  11. #11
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    Seems a weird value to assign to 12:33 (I presume PM) 300 implies production started at 7:33AM - why not 7:00AM?

    from what you have provided, you could do this with a simple formula

    as a time value, subtract 7:03 from your time and format as minutes. On my phone so cannot provide the actual formula at the moment

  12. #12
    sseniour is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2019
    Posts
    10
    time starts at 06:36 and but there are breaks throughout the day and evening. For instance 15:15 = 450 and 19:21 = 451, so not sure a simple formula would work. That is why I set up a table to equate time of day to # of prod mins

  13. #13
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    You are using spaces in field names and no square brackets.
    Please read any replies.
    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

  14. #14
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    time starts at 06:36 and but there are breaks throughout the day and evening. For instance 15:15 = 450 and 19:21 = 451, so not sure a simple formula would work.
    So a 4hr+ break in the afternoon?

    assuming your date fields are datetime and not text then your formula might look like this (done in the immediate window)
    ?(#12:33#-(#06:36#+iif(#12:33#>#08:00#,#00:57#,0)+iif(#12:33 #>#15:15#,#04:05#,0)))*24*60
    300



    or for later in the day
    ?(#21:05#-(#06:36#+iif(#21:05#>#08:00#,#00:28#,0)+iif(#21:05 #>#15:15#,#04:05#,0)))*24*60
    596


    add more iifs as required - but probably easier to manage in a function

    #12:33# and #21:05# are the times you are trying to get the minute count
    #06:36# is your production start time
    #08:00# and #15:15# are the start of your breaks
    #00:28# and #04:05# are the lengths of the breaks

    Are you aware for what a datetime field actually is? it is a double type number, the value before the decimal point is the number of days since 30/12/1899 (which is zero). and the part after the decimal point is the time in seconds divided by 86400, the number of seconds in a day (24*60*60)

    So now
    ?cdbl(now())
    45898.0368055556

    ?cdbl(date())
    45898

    ?cdbl(#12:00#)
    0.5

    all you are seeing with 12:00 or any other time is a format, not the actual underlying value


    So all you are doing is adding and subtracting numbers

  15. #15
    sseniour is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2019
    Posts
    10
    I do have spaces in field names and I have those enclosed in brackets?? Am I not supposed to do that?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Lookup values not appearing in Lookup field?
    By dominover in forum Access
    Replies: 4
    Last Post: 03-05-2016, 05:01 PM
  2. Replies: 4
    Last Post: 07-28-2015, 10:14 AM
  3. Replies: 3
    Last Post: 05-08-2015, 11:08 AM
  4. Replies: 5
    Last Post: 11-24-2014, 02:19 PM
  5. Replies: 5
    Last Post: 06-25-2014, 09:19 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