How get autonumber key after adding a new row ??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm coding a huge conversion routine in VBA. After I add a record to one table I need to create a row in another table with the autonumber key in a linked column. How do I get the autonumber key of a record I have just added?
 
How are you adding the new record? If via DAO.Recordset variable, you can do
this to put that autonumber value into the lngANumber variable:

Dim rst As DAO.Recordset, lngANumber As Long
Set rst = CurrentDb.OpenRecordset("Name", dbOpenDynaset)
rst.AddNew
rst!Fieldname = 'value'
rst.Update
rst.Bookmark = rst.LastModified
lngANumber = rst!AutonumberFieldName
rst.Close
Set rst = Nothing

--
Ken Snell
<MS ACCESS MVP>

David said:
I'm coding a huge conversion routine in VBA. After I add a record to one
table I need to create a row in another table with the autonumber key in a
linked column. How do I get the autonumber key of a record I have just
added?
 
Hello Bongo,

I am just checking on your progress regarding the information that was sent
you. Have you tried the steps Ken provided to you? We wonder how the
testing is going. If you encounter any difficulty, please do not hesitate
to let us know.

Please post here and let us know the status of your issue. Looking forward
to hearing from you soon. Thanks!

Billy Yao
Microsoft Online Support
 
Back
Top