get id from last inserted row

ramone

Active member
Joined
Sep 29, 2005
Messages
26
hello,

how can i get the value of the autonumeric key field for the last inserted row in an ms access database using odbc (something like mysqls mysql_insert_id() function)??

thank you
 
Hi!
Im not so sure you can...
The only way I know of is to read the table just after the insert is done.

But there is one catch...
Access isnt a multiuser database by design and thus there are no functions to handle such things as multiple inserts at the same time. Rows will most likely be inserted but you cant be sure that youre the one that inserted last record.

You could try to use transaction handling to insert, retrieve the record with the latest ID and try to match your values with that record and commit if they match and rollback if they dont and loop until youre done.
Ought to work but I havent tried it, only use Access for single user applications.

HTH
/Kejpa
 
Back
Top