Sub TestTransaction()
Dim cnConnection As New ADODB.Connection
Dim cmdCommand As New ADODB.Command
Set cnConnection = CurrentProject.Connection
cmdCommand.ActiveConnection = cnConnection
On Error GoTo HandleError
cnConnection.BeginTrans
cmdCommand.CommandText = "UPDATE tblContacts SET FirstName = 'Test' WHERE ContactId = 1"
cmdCommand.Execute
cmdCommand.CommandText = "UPDATE tblContacts SET ContactId = 'A' WHERE ContactId = 1"
cmdCommand.Execute
cnConnection.CommitTrans
Exit Sub
HandleError:
cnConnection.RollbackTrans
MsgBox "An error occurred: " & Err.Description
End Sub
|