
Getting the New AutoNumber ID in Microsoft Access VBA
transcript
show notes
When VBA adds a new record in Microsoft Access, you often need the AutoNumber ID immediately afterward. That ID lets you open the exact order, customer, or log entry your code created instead of guessing based on the highest number or the newest-looking row.
In this episode, Richard explains why relying on Max(ID), sort order, or the last record in a form can fail in a multi-user database. Someone else may add a record at nearly the same time, leaving your code pointed at the wrong row without producing an obvious error.
The discussion uses a recordset and AddNew example from a food log database, showing the basic idea of returning the newly assigned ID from a function. With that key in hand, your calling code can reliably find the new record, move the form to it, or use it to create related records after the save succeeds.