• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 71
  • Last Modified:

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.
0
HLRosenberger
Asked:
HLRosenberger
1 Solution
 
[ fanpages ]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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now