Search code examples
vbams-accessms-access-2007

Get Most Recent Record


The question speaks for itself, for the most part. I have 2 fields in a table, Date and Value. By the most recent date, I would like to use the dollar value. I would like to get these values by means of VBA code.

Is this possible with a DLookup or DMax, or something similar?

What I have now searches dates quarterly, however quarterly is not the correct solution I've come to figure out, as the quarterly updates are sent out too late to use.


Solution

  • You can use TOP 1 in a query sorted by Date in descending order.

    SELECT TOP 1 y.Date, y.Value
    FROM YourTable AS y
    ORDER BY y.Date DESC;