Solved

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

Posted on 2016-10-12
3
54 Views
Last Modified: 2016-10-12
How can I get back the  Primary Key of the last inserted record, using OLEDB connection.
0
Comment
Question by:HLRosenberger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 500 total points
ID: 41840572
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
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 41840575
Thanks!
0
 
LVL 20
ID: 41840581
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question