DLookup Top 1 (1 Viewer)

penfold1992

Registered User.
Local time
Today, 11:37
Joined
Nov 22, 2012
Messages
169
I'm looking for a way to find:

["ID"] in Requests
where the criteria is the Max ["Created Date"] (the entry with the most recent date)

is this possible with DLookup or should it be done using SQL?
 

namliam

The Mailman - AWF VIP
Local time
Today, 12:37
Joined
Aug 11, 2003
Messages
11,695
I would avoid DLookup whenever possible... go go SQL
 

penfold1992

Registered User.
Local time
Today, 11:37
Joined
Nov 22, 2012
Messages
169
I would avoid DLookup whenever possible... go go SQL

Code:
SQLstr = "SELECT TOP 1 [ID] FROM [Backup] ORDER BY [Created Date] Desc"
    
Set rs = dbs.OpenRecordset(SQLstr)
    
    Debug.Print rs.Fields(0)

This is what ive tried... but I cant seem to get the correct output I expect..
 

pr2-eugin

Super Moderator
Local time
Today, 11:37
Joined
Nov 30, 2011
Messages
8,494
How about?
Code:
strSQL = "SELECT TOP 1 Backup.ID FROM Backup " & _
         "WHERE Backup.[Created Date] IN (SELECT Max(Backup.[Created Date]) AS MaxOfCreated FROM Backup);"
Set rs = dbs.OpenRecordset(SQLstr)
Debug.Print rs.Fields(0)
 

Users who are viewing this thread

Top Bottom