?
Solved

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

Posted on 2016-10-12
3
Medium Priority
?
67 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 2000 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 22
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

719 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