View Full Version : How do I get the newly created key?


electro
06-27-2007, 11:14 PM
I have tables which I add a new post to. But I want to find its key. DoCmd.GoToRecord , , acNewRec
'Lot of data fills out the different textboxes
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Requery
When I first save the data and the requery the you should expect the ID field on form to have the new unique number but it doesnt. Can you get the current unique ID on some other way?

wazz
06-28-2007, 12:34 AM
the ID field should automatically increase as soon as you start to enter data. are you sure the form is bound to a table or query?
to save i usually use:docmd.runcommand accmdsaverecord
then you should be able to reference the ID by:me.IDfieldcontrol
does this change anything?

electro
06-28-2007, 12:54 AM
the ID field should automatically increase as soon as you start to enter data. are you sure the form is bound to a table or query?
to save i usually use:docmd.runcommand accmdsaverecord
then you should be able to reference the ID by:me.IDfieldcontrol
does this change anything?
Dont know why but replacing
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
with
DoCmd.RunCommand acCmdSaveRecord
solved it.

Whats the difference between the two?
Thanks for your help