Hi. I am logging an import process and after creating the import record in the log table I want to use the id of that record later. I thought I could do this using @@identity and used the following code, however the value of autoID, when executed, is not tblTfrLog - it is an ID from another table. No other users on this db.
Where / what needs to be fixed?
Where / what needs to be fixed?
Code:
strSQLLog = "INSERT INTO tblTfrLog ( TfrSubType, TfrType, ImportStage, DateInitiated)" _
& " VALUES ('" & LogSubType & "' , 'Import', 'Stage 3 Start', #" & Format(LogDate, "yyyy-mm-dd hh:mm:ss AM/PM") & "#)"
Set db = CurrentDb
Set rs = db.OpenRecordset("tblTfrLog")
' Debug.Print strSQLLog
DoCmd.RunSQL strSQLLog
'Retrieve the last inserted ID
'Store the ID in a variable
Set rs = db.OpenRecordset("SELECT @@IDENTITY")
autoID = rs(0)
Debug.Print autoID
rs.Close