Hi,
When I start my switchboard (main page) I need to check a table for the last record (row) programatically, how to do that?
Hi,
When I start my switchboard (main page) I need to check a table for the last record (row) programatically, how to do that?
How do you determine last row? autonumber, date/time ?
DMAX() would get you a field or several. If you need more than two or 3, I would use a recordset and perhaps a SELECT TOP 1 and order as needed.
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba
What exactly determines "last"? Please tell us more.
after making a new record it is saved last in the table, how to access last record in a table programatically?
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba
Records are stored in a table in no specific order-- very much like marbles in a bag. Order of retrieval/selection is based on a query "Order BY" clause. We need to know what LAST means to you to provide more focused response.
Merely repeating your requirement over and over again is not helpful.how to access last record in a table programatically?
What data within the record itself defines that it is the last? A date? an Invoice Number? A primary key value?
You cannot reliably and consistently use the position of the record in the table to determine if it is the last.
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("SELECT TOP 1 * FROM Turns ORDER BY ID DESC")
MsgBox ("Last Turn: " & rs!Person & " On " & rs!TheTime)
rs.Close
Set rs = Nothing
Make the recordsource for the form a query string.
"Select * from turns order by ID DESC"
Best to always qualify your objects.
Code:Dim rs As DAO.Recordset
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba