Having a hard time with Dmax

Montez659

Well-known Member
Joined
May 4, 2005
Messages
918
Not even sure if that is what I need. What I do need is to return the record ID (transID) of the record where the date is the most recent (transDTStamp). So far, I can get it to return the date, but I can't figure out how to modify it to return the record ID.
Code:
a = DMax("transDTStamp", "tblTransactions")
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
You can't do it just with DMax.

In a query you would probably use a subquery.

Perhaps you could try something similar using DMax and DLookup.
 
Upvote 0
Not quite, but that might work I suppose.:)
 
Upvote 0
It works, but I am interested in how you would do it. I kind of pieced this together from several different sources so who knows how stable it is (SQL isn't necessarily my strong point). This is what the Query looks like, then I did a DLookup on that query, as it would only contain one record.
Code:
SELECT tblTransactions.transID
FROM tblTransactions
WHERE (((tblTransactions.transDTStamp)=(select max([transDTStamp]) from tblTransactions)));
 
Upvote 0
I'd use what I suggested DMax and DLookup.

DMax to get the date for the criteria of the DLookUp which returns the ID.
 
Upvote 0
Oh, ok, gotcha. It just clicked what you are saying. Essentially, return the date off of the DMax, and then use that as criteria for the DLookup. I like that way better, much smaller. Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,718
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top