Obtaining Primary Key After Insert Command

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
 
M

Michel Walsh

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
 
K

Kevin Sprinkel

Thanks, Michel.

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top