Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 24th, 2006, 02:03 PM
Registered User
 
Join Date: Oct 2005
Location: , , .
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
Reply With Quote
  #2 (permalink)  
Old June 5th, 2006, 02:41 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
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>
                          )
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 02:18 PM
Record is Inserted Twice donevco Access 1 February 27th, 2007 11:28 AM
How to Grab ID of a recently "inserted item" rsearing ASP.NET 2.0 Professional 11 February 15th, 2007 02: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



All times are GMT -4. The time now is 12:44 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.