views:

327

answers:

1

I have a button click event that takes information from controls and enters it into a table via INSERT INTO SQL statement in VBA.

I was wondering if there is anything I could add to this, or some other method to acquire the record number that is created for the record?

Could I just turn around and SELECT against the table and use rs.last?

+1  A: 

You can "SELECT @@IDENTITY" from the same DAO.Database object variable where you previously executed your INSERT statement. See here on Stack OverFlow for details.

HansUp
thanks as always HansUp!
Justin
so HanUps, how would I then take the value I have retrieved and assign it back to a control? lets say this exists after my query ( "SELECT @@ IDENTITY"), and I want to show that value in a text box on my form ("textReturn").....what variable, or container does it exist in right now? newRow?
Justin
@HansUp...nevermind, I see that it is simple after that. Thanks very much for your help....this is exactly what I needed!
Justin
For code that does this see http://stackoverflow.com/questions/1628267/autonumber-value-of-last-inserted-row-ms-access-vba#1633346
David-W-Fenton
@David...yeah that was exactly the exact same answer I was refering to. I was able to use it, and it worked great. Exactly what I needed. Thanks!
Justin