Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning AutoNumber Values 2

Status
Not open for further replies.

mattygriff

Programmer
May 14, 2001
350
GB
When I create a new entry into a table with an AutoNumber field, is there a way of simultaneously returning the value of the AutoNumber without doing a separate SELECT?

Thanks.
 
Let's say you're using ADO, then the following insert and retrieval of identity should work (note - Jet 4.0) - the identity will retrieve the last inserted autonumber on this connection:

[tt]dim rs as adodb.recordset
dim strSsql as string
strSsql="insert into mytable (field1, field2) values ('test1', 'test2')"
currentproject.connection.execute strSql
set rs=currentproject.connection.execute("select @@identity")
debug.print rs.fields(0).value[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top