Getting primary key from record added with SaveRecord

johnmcd

New member
Local time
Today, 18:24
Joined
Dec 31, 2007
Messages
5
Hi all,

I have a VBA module that runs on the 'click' event for a button on a form that's opened in 'Add' mode (a typical 'Add' button). In the module I use the command:

DoCmd.RunCommand acCmdSaveRecord

to save the record, and that's working just fine. However, in that same VBA module, I then want to add a record to another table for audit purposes, including the primary key of the record I just added with DoCmd. How can I get the primary key (it's an auto-generated number) from (or after) the DoCmd?

Thanx.

John
 
Is this a bound form or an unbound form? If bound you should be able to get the value from the field in the Before Update event of the form as the autonumber is assigned right at the time you start entering data.
 
Bob,

Perfect - that's exactly what I needed. Yes, it's a bound field/form, but I didn't realize that the autonumber was set in the form prior to saving and that I had access to it.

Thanx!

John
 

Users who are viewing this thread

Back
Top Bottom