TheScripts Tip of the Week #19 - DAO Transaction Processing
In this Tip, we'll concentrate on the ADO aspect of this process. The below listed code shows the basic, skeletal format, for Transaction Processing in ADO:
Expand|Select|Wrap|Line Numbers
- On Error GoTo Err_Handler
- Dim cnn As ADODB.Connection
- Dim blnInTrans As Boolean
- blnInTrans = False 'not in a Transaction as of yet
- Set cnn = CurrentProject.Connection
- '...
- cnn.BeginTrans
- blnInTrans = True 'now in the beginning of a Transaction
- 'any series of data changes 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
- End If
- 'further Error processing here
- Resume Exit_Handler