Connecting Tech Pros Worldwide Forums | Help | Site Map

ADO Transaction Processing

ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,214
#1   Jul 14 '07
In the Tip of the Week #19, we demonstrated Transaction Processing, specifically as it applies to DAO (Data Access Objects). In this week's Tip, we'll illustrate how Transaction Processing can be used within the context of ADO (ActiveX Data Objects). Please refer to the Link below if you wish to see an Overview of Transaction Processing, how it is implemented within DAO, or special issues to be aware of when utilizing Transaction Processing in general.

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
  1. On Error GoTo Err_Handler
  2. Dim cnn As ADODB.Connection
  3. Dim blnInTrans As Boolean
  4.  
  5. blnInTrans = False        'not in a Transaction as of yet
  6. Set cnn = CurrentProject.Connection
  7. '...
  8.  
  9. cnn.BeginTrans
  10.   blnInTrans = True       'now in the beginning of a Transaction
  11.   'any series of data changes here
  12. cnn.CommitTrans
  13.   blnInTrans = False      'Transactions completed without Error
  14.  
  15. '...
  16.  
  17. Exit_Handler:
  18.   Exit Sub
  19.  
  20. Err_Handler:
  21.   If blnInTrans Then      'in the midst of a Transaction
  22.     cnn.RollbackTrans     'Restore data to pre-Transaction state
  23.   End If
  24.   'further Error processing here
  25.   Resume Exit_Handler
NOTE: You can see that the code is very similar to the DAO version, except that the Transaction Processing Methods in ADO, (BeginTrans, CommitTrans, and RollbackTrans), are Methods of the Connection Object rather than the Workspace Object in DAO. In addition, the DAO RollBack Method is named RollbackTrans in ADO.



Reply