I am using transactions in my MS Access VBA code. I update one of my fields, the Incoming_Pieces
field in my Inventory table. Then, before committing the transaction, I use DLookup
on the updated field. The DLookup
function will return the value before the transaction, not the value updated during the transaction before committing.
Is this intended? There's no error message or any warning that the data I am retrieving is out of sync with the data being updated within the transaction.
Is the only workaround to generate a SELECT
statement instead of DLookup?
Here's my testing code to prove this.
Public Function testTransaction()
Dim pieces As Variant
pieces = DLookup("Incoming_Pieces", "Inventory", "Code='MT-1-1000x1x1'")
Debug.Print (pieces) ' <------------ prints 0
DAO.DBEngine.BeginTrans
Dim sql As String
sql = "UPDATE Inventory SET Incoming_Pieces = 10 WHERE Code='MT-1-1000x1x1'"
CurrentDb.Execute (sql)
pieces = DLookup("Incoming_Pieces", "Inventory", "Code='MT-1-1000x1x1'")
Debug.Print (pieces) ' <------------ prints 0
DAO.DBEngine.CommitTrans
pieces = DLookup("Incoming_Pieces", "Inventory", "Code='MT-1-1000x1x1'")
Debug.Print (pieces) ' <------------ prints 10
End Function