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

ms-access, vba

Solution

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

Problem

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?

Original source