Results 1 to 6 of 6
  1. #1
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568

    Dlookup function with max condition

    Hi Guys,



    I am trying to retrieve SchemaName from table t_currentschema where Date is the newest one.

    How can i do this?

    I tried:

    Code:
    select DLookup("[UserSchema]", "t_currentschema", "[UserInputDate] =" & max(UserInputDate)
    but this is not working.

    Please help,
    Jacek

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    DMax(...)

    dlookup not needed since DMax IS the dlookup.

  3. #3
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Hi,

    thank you.

    I tried to use:

    Code:
    SchemaName = DLookup("[UserSchema]", "t_currentschema", "[UserInputDate]=#" & DMax("[UserInputDate]", "t_currentschema") & "#")
    where Dmax =

    Click image for larger version. 

Name:	Screenshot_26.png 
Views:	19 
Size:	9.8 KB 
ID:	34613

    i am getting error:

    Click image for larger version. 

Name:	Screenshot_28.png 
Views:	19 
Size:	31.1 KB 
ID:	34614

    Click image for larger version. 

Name:	Screenshot_27.png 
Views:	19 
Size:	15.4 KB 
ID:	34615

    please help,
    Jacek

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    To use dates in expressions, you need mm/dd/yyyy or yyyy-mm-dd format
    In your case, also add the time part - mm/dd/yyyy hh:nn:ss

    Code:
    SchemaName = DLookup("UserSchema", "t_currentschema", "UserInputDate=#" & Format(DMax("UserInputDate", "t_currentschema"), "mm/dd/yyyy hh:nn:ss") & "#")
    You might be better doing this in two steps - get the latest UserInputDate then get the schema name

    Code:
     Dim dteDate As Date    
    dteDate = DMax("UserInputDate", "t_currentschema")
    SchemaName = DLookup("UserSchema", "t_currentschema", "UserInputDate=#" & Format(dteDate, "mm/dd/yyyy hh:nn:ss") & "#")
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Perhaps
    Code:
    SELECT UserSchema from t_currentschema
    where userInputDate = (select Max(userInputDate) from t_userSchema)

  6. #6
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Hi Guys,

    thank you.
    Works like a charm.

    Code:
    TempDate = DMax("[UserInputDate]", "t_currentschema")
    
    
    SchemaName = DLookup("[UserSchema]", "t_currentschema", "[UserInputDate]=#" & Format(TempDate, "yyyy-mm-dd hh:nn:ss") & "#")
    very strange syntax

    Best,
    Jacek

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

Similar Threads

  1. Replies: 6
    Last Post: 06-07-2017, 11:35 AM
  2. Replies: 2
    Last Post: 09-24-2016, 11:29 PM
  3. Replies: 4
    Last Post: 01-12-2015, 12:07 AM
  4. DLookup with multiple field condition
    By agent- in forum Programming
    Replies: 4
    Last Post: 10-15-2011, 05:17 PM
  5. DlookUp Function.
    By cap.zadi in forum Forms
    Replies: 11
    Last Post: 09-22-2011, 12:56 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