Get record written data
Posted on 2016-07-18
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
'determine MAX Lot ID number
intMaxLotId = DLookup("MaxOfTestLotID", "tblMaxLotID")
'Prompt user with MAX Lot ID Number.
MsgBox "Lot number " & intMaxLotId & " has been created.", , "ATE DATABASE"
'open switchboard and close initial form
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.