Justin Tanner
Justin Tanner

Reputation: 14352

How do I get the auto number after an INSERT in Ms Access?

I have the following query in VBA:

DoCmd.RunSQL "INSERT INTO table (value) VALUES ('example')"

( with an auto incremented primary key called id)

How can I get the auto incremented id generated by this insert?

Upvotes: 2

Views: 7654

Answers (1)

MJ Hufford
MJ Hufford

Reputation: 634

I believe you're looking for:

@@Identity

It's similar to SCOPE_IDENTITY in T-SQL. Check out this article for more info:

http://www.mikesdotnetting.com/Article/54/Getting-the-identity-of-the-most-recently-added-record

Upvotes: 7

Related Questions