I currently use the following VBA code to get the MAX record just after commit:
<BEGIN VBA> Dim strSQLLot As String
Dim strSQLFailure As String
Dim intFailed As Integer
Dim intCounter As Integer
Dim dbConn As ADODB.Connection
Dim recSet As ADODB.Recordset
Dim intNextFailureId As Integer
Dim intArray() As Integer
Dim dbs As DAO.Database
Dim rsSQL As DAO.Recordset
Dim intMaxLotId As Integer
Dim intNewLotID As Integer
'Open the database
Set dbConn = CurrentProject.Connection
'Write the form's data to the SQL table tblInitialData
DoCmd.RunCommand acCmdSaveRecord
'determine MAX Lot ID number
DoCmd.RunMacro "mcrRunqryMaketblMaxLotID"
intMaxLotId = DLookup("MaxOfTestLotID", "tblMaxLotID")
'Prompt user with MAX Lot ID Number.
MsgBox "Lot number " & intMaxLotId & " has been created.", , "ATE DATABASE"
DoCmd.Close
'open switchboard and close initial form
DoCmd.OpenForm "Switchboard"
<END VBA>
I previously tried to get a SELECT statement to run but had no luck. I would like to use either SCOPE_IDENTITY() or @@IDENTITY but cannot determine the correct VBA to make that run. Indeed, will it even run in scope based on using the DoCmd.RunCommand acCmdSaveRecord statement instead of an INSERT INTO statement? I have tried DoCmd.OpenQuery, CurrentDb.Execute, and others that apparently do not allow SELECT statements.
TIA,
Tim