Results 1 to 4 of 4
  1. #1
    FL0XN0X is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Location
    Belgium
    Posts
    84

    Dlookup with Date criteria always return 0

    Dear,

    I have a Query with the name 'Finale Capaciteit' that holds 3 columns:
    column1: Datum (contains a date)
    column2: Totale Forecast VM (contains a number)
    column3: Totale Forecast NM (contains a number)

    This query is populated with data.

    In the 'on click' event of a Command Button on a Form, I want to retrieve data form this Query, so my code in vba looks like:

    Dim Datum As Date
    Datum = DateSerial(Keuzelijst602.Value, 1, BeginOfMonthJan) ----> here I populate the variable Datum with the date that must be lookup'ed in the Query and return the corresponding value in column [Totale Forecast VM]"
    Capacity = DLookup("[Totale Forecast VM]", "[Finale Capaciteit]", "[Finale Capaciteit].Datum=Datum")

    Although the query contains data different from 0 for a given date, my Dlookup function ALWAYS returns 0 ....while the corresponding column [Totale Forecast VM] contains data <> 0

    Is the code wrong?

    Thank you in advance
    Kind regards,
    Bart

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,842
    when using dates as string in sql you need to:

    1. use the # char in order to tell sql that the text between them is to be treated as a date
    2. sql only recognises the US format for dates of month/day/year
    3. as written, your criteria is not built correctly, it is trying to compare your field with a value of 'Datum', not a date

    so instead of

    "[Finale Capaciteit].Datum=Datum"

    try

    "[Finale Capaciteit].Datum=#" & format(Datum,"mm/dd/yyyy") & "#"

  3. #3
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,700
    Try this:
    Code:
    Capacity = DLookup("[Totale Forecast VM]", "[Finale Capaciteit]", "[Finale Capaciteit].Datum=" & Datum)

  4. #4
    FL0XN0X is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Location
    Belgium
    Posts
    84

    Thumbs up

    Ajax, just did the test and it works !!!!!!!!!!!!!!!!!

    Thank you !!!!

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

Similar Threads

  1. Replies: 6
    Last Post: 10-25-2016, 01:11 PM
  2. Replies: 4
    Last Post: 03-23-2012, 01:18 PM
  3. Replies: 1
    Last Post: 06-17-2011, 12:59 AM
  4. Return DLookup result as date?
    By kman42 in forum Access
    Replies: 8
    Last Post: 04-22-2011, 11:35 AM
  5. Dlookup to match two criteria and return value
    By randolphoralph in forum Programming
    Replies: 20
    Last Post: 05-20-2010, 12:27 PM

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