When inserting a record, I need to somehow return the AutoID that was generated for that record. I'm using ADO to connect to Access. What is the correct way of insuring that I return the correct ID? Thanks!
Printable View
When inserting a record, I need to somehow return the AutoID that was generated for that record. I'm using ADO to connect to Access. What is the correct way of insuring that I return the correct ID? Thanks!
If you are opening a recordset whit OpenKeySet, and you add a record, this autonumber field is already filled, with the correct number
Sorry, I guess I wasn't clear. I'm executing an insert query, not opening a recordset. So how would I do it then? It is important to note that this is a multi user app meaning return MAX id is not going to work. I know I could do a timestamp check, but the problem with that is that it's entirely possible that 2 people insert a record within a few milliseconds of each other, thus causing a duplicate timestamp since a timestamp only goes down to seconds, correct? Also, there will be no user id envolved. So what's the best way for 1 particular client to retrieve the newly created ID?
After the insert statement execute a Select @@Identity.
VB Code:
oConn.Execute("Insert Into ....") Set oRsIdent = oConn.Execute("Select @@Identity") debug.print oRsIdent(0).Value