Solved

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

Posted on 2016-10-12
3
59 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 21
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

617 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