Wrox Programmer Forums
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 24th, 2006, 02:03 PM
Registered User
 
Join Date: Oct 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Last record inserted ID

In an access database I have a table with the ID set for autoincrement. I am inserting a record using DoCmd.RunSQL
Is there an easy way to find out the ID number of the record after I insert it? I need to referance the record right after I create it.

in MS SQL I use @@IDENTITY is there something similar.

Thanks

Dwayne http://www.adacprogramming.com
http://www.topwebsitetips.com
 
Old June 5th, 2006, 02:41 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

No there isn't.

To do this, you will need to add information yourself, and look up the record using that info.

For instance, you could add an "INSERT_DATE_TIME" column, and fill it in with NOW() as you add the record.

Then of course you could retrieve the most recent record with something like:
Code:
SELECT ID
FROM  <MyTable>
WHERE  INSERT_DATE_TIME = (  SELECT MAX(INSERT_DATE_TIME)
                             FROM   <MyTable>
                          )





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Edit record right after it was Inserted? aladov ASP.NET 2.0 Professional 4 December 11th, 2007 03:18 PM
Record is Inserted Twice donevco Access 1 February 27th, 2007 12:28 PM
How to Grab ID of a recently "inserted item" rsearing ASP.NET 2.0 Professional 11 February 15th, 2007 03:45 PM
Get most recently inserted ID code mat41 Classic ASP Professional 17 May 2nd, 2006 02:19 AM
Getting ID from inserted data in Access chrscote Classic ASP Databases 6 June 23rd, 2005 02:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.