Obtaining Primary Key After Insert Command

  • Thread starter Thread starter Kevin Sprinkel
  • Start date Start date
K

Kevin Sprinkel

After inserting two fields of a new record as part of a
NotInList procedure, neither of which is the primary key,
I'd like to open an input form to that record to add the
other fields. Is there any way to obtain the
automatically-assigned primary key value, or must I use a
compound Where criteria in the OpenForm method?

TIA
Kevin Sprinkel
 
Hi,


With DAO, the number is assigned as default value, so, it should be
available as usual, in the field.

Dim rst As DAO.Recordset

...

rst.AddNew
... = rst.Fields("MyAutonumberField").Value
...
rst.Update


Dot-mdb forms are based on DAO, so if the form is bound to a record
source, and you are appending a new record, I would try to read the value as
if it was from a field (and I would probably add a hidden control on the
form, hidden control associated to that autonumber field... not hidden if I
need to see it, in a visual debugging stage).



Hoping it may help,
Vanderghast, Access MVP
 
Thanks, Michel.

With DAO, the number is assigned as default value, so, it
should be
 
Back
Top