Access Database, Return Priimary Key of the last inserted record, using OLEDB connection.

How can I get back the  Primary Key of the last inserted record, using OLEDB connection.
LVL 1
HLRosenbergerAsked:
Who is Participating?
 
[ fanpages ]Connect With a Mentor IT Services ConsultantCommented:
Is the Primary Key an Auto-Increment (Long Integer) column?

If so, & assuming the INSERT was performed programmatically (rather than through the MS-Access application's Graphical User Interface) then executing (within the same Connection Object as the INSERT) the SQL Statement "SELECT @@Identity" & retrieving the value of the resultant recordset value will provide the last key used.

Some discussion in this previous question thread:
[ https://www.experts-exchange.com/questions/22577304/Access-VBA-SELECT-IDENTITY-question.html#a19105733 ]
0
 
HLRosenbergerAuthor Commented:
Thanks!
0
 
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
you can also do this:
once you update the record:
rs.bookmark=rs.LastModified
myVariable = rs!AutonumberFieldname

Open in new window

WHERE rs = recordset variable
AutonumberFieldname is the fieldname of the AutoNumber field
0
All Courses

From novice to tech pro — start learning today.