Fix Microsoft Access Last Function Not Returning the Latest Date
Question details
The user needs to retrieve the most recent visit date or record for each client in Microsoft Access.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- A grouped query uses First and Last to find client visit dates and times.
- Observed behavior
- Last does not reliably return the latest date or time in each client group.
Check that the visit date and time fields use the Date/Time data type and identify the client ID field that links the tables. Decide whether you need only the maximum values or the complete row associated with the latest visit.
Use Max to Return the Latest Date for Each Client
Use this approach when you need the latest date or time values for each client, rather than an entire visit record.
In Microsoft Access, open the query in Design View, then choose View > SQL View.
Enter a grouped query such as: SELECT Clients.ClientID, Clients.FirstName, Clients.LastName, Max(VisitsLog.DateTimeIn) AS LatestIn, Max(VisitsLog.DateTimeOut) AS LatestOut FROM Clients INNER JOIN VisitsLog ON Clients.ClientID = VisitsLog.ClientID GROUP BY Clients.ClientID, Clients.FirstName, Clients.LastName; Adjust the table and field names to match your database.
Select Run on the query toolbar and check the latest values returned for each client.

Use a Correlated Subquery to Return the Latest Visit Record
Use this method when you need the complete visit row associated with the latest date and time for each client.
Review Exported Access Data in WPS Spreadsheets
WPS Office is a free, lightweight Office alternative with a familiar interface for working with exported data. Export Access query results to an Excel workbook to review them in WPS Spreadsheets; WPS does not fix or run Access database queries.

Frequently Asked Questions
Why doesn't Last return the most recent date in Access?
Last returns a value based on the records encountered by the query, not necessarily the greatest date. Use Max on the Date/Time field to find the latest value in each group.
How do I find the latest date for each client?
In a grouped query, include ClientID in the GROUP BY clause and use Max on the visit date field. Run the query from SQL View to see the latest value for each client.
How can I get other fields from the latest visit row?
Use a correlated subquery that compares each visit's date with Max of the date for the same ClientID. Selecting T1.* returns the fields from matching visit rows.
What happens if two visits have the same latest timestamp?
The correlated subquery returns both rows because each matches the maximum timestamp. Add a suitable tie-breaking rule if you need exactly one row.
Do Max(DateTimeIn) and Max(DateTimeOut) always describe the same visit?
No. Each Max is calculated independently, so the values may come from different rows. To keep visit fields together, select the latest row using a correlated subquery.




