Retrieve autonumber

E

Efrain Flores

Hi :

I would like to know how to retrieve the autonumber value assigned by access
2002 using vba. If you know any online resources wher I can find this or you
have any code that could help me, I will really appreciate it

Thank you
 
A

Allen Browne

You cannot retrieve the AutoNumber assigned by an append query statement,
but you can get the number if you append the value using DAO.

This example assumes that MyTable has an AutoNumber key named "ID":

Dim rs As DAO.Recordset
Set rs= dbEngine(0)(0).OpenRecordset("MyTable", dbOpenDynaset, dbAppendOnly)
rs.AddNew
!SomeField = SomeValue
MsgBox "The number you will get is " & rs!ID
rs.Update
rs.Close
Set rs = Nothing
 
Top