tags:

views:

28

answers:

1

I have query in vba like this:

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?

+4  A: 

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

MJ Hufford
Wow, I did not know this! I've been doing SELECT Max(Field) for ever. I notice the samples are ADO.NET, does this also work in classic ADO?
Simon