I need to get the Autonumbered ID of the last record inserted into a table (through INSERT INTO command)
I have seen some methods in the forum that looks to work for most of the community but not in my case: Autonumber value of last inserted row - MS Access / VBA
Dim miDDBB As DAO.Database
.....
StrSQL = " INSERT INTO DG_tb_Main " ......
Set miDDBB = CurrentDb
miDDBB.Execute (StrSQL)
newRow = miDDBB.OpenRecordset("SELECT @@IDENTITY")(0)
Set db = Nothing
When using this code I always get the 'newRow' value as '0'. I have checked the SQL expresion and works fine, insterting the new record into the table. ¿What am I doing wrong?
Regards