On Error GoTo Err_Handler
Dim cnn As ADODB.Connection
Dim blnInTrans As Boolean
blnInTrans = False 'not in a Transaction as of yet
cnn = CurrentProject.Connection
'...
cnn.BeginTrans()
blnInTrans = True 'now in the beginning of a Transaction
'Do your delete here
'Do your insert here
cnn.CommitTrans()
blnInTrans = False 'Transactions completed without Error
'...
Exit_Handler:
Exit Sub
Err_Handler:
If blnInTrans Then 'in the midst of a Transaction
cnn.RollbackTrans() 'Restore data to pre-Transaction state
' This will restore the data deleted by your DELETE query
End If
'further Error processing here
Resume Exit_Handler
|