Hello all!
After some initial attempts to use SCOPE_IDENTITY() with Access internal DB-engine, I have realized that Acess does not support this function.
So I have to use the @@IDENTITY to get that latest AutoIncrement PK of a table that is updated by a form.
Unfortunately, I dont know what object to use to get my hands on the @@IDENTITY that was generated by the forms insert. I have tried the code below (in the AfterInsert-event of the form that inserts new rows)
It executes without errors, but always returns zero, problably because the the object used by the form for posting the insert is not the same as CurrentDB.OpenRecordSet.
Any ideas?
After some initial attempts to use SCOPE_IDENTITY() with Access internal DB-engine, I have realized that Acess does not support this function.
So I have to use the @@IDENTITY to get that latest AutoIncrement PK of a table that is updated by a form.
Unfortunately, I dont know what object to use to get my hands on the @@IDENTITY that was generated by the forms insert. I have tried the code below (in the AfterInsert-event of the form that inserts new rows)
Code:
Dim lpRowIdRecordSet As DAO.recordSet
Set lpRowIdRecordSet = CurrentDb.OpenRecordset("SELECT @@IDENTITY AS row_id;")
MsgBox "After insert @@IDENTITY = " & lpRowIdRecordSet.Fields("row_id").Value
Any ideas?