Retrieve the Record ID Just Inserted

S

Samuel Shulman

Hi

Is there a way or retrieving the record ID of a record just added within the
same SQL statement or similar method

I am new to Access and in SQL Server one can use the @@Identity method

Thank you,
Samuel
 
R

RoyVidar

Samuel Shulman said:
Hi

Is there a way or retrieving the record ID of a record just added
within the same SQL statement or similar method

I am new to Access and in SQL Server one can use the @@Identity
method

Thank you,
Samuel

If you use ADO to do your insert, you can keep using @@identity to
retrieve the last autonumber (identity), but you need separate
statements on the same connection (wouldn't you use scope_identity()
on SQL server?). Air code

cn.execute "INSERT INTO ....",, adCmdText+adExecuteNoRecords
set rs = cn.execute("SELECT @@Identity", , adCmdText)
debug.print rs.fields(0).value
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top