Multiple Queries Using Transactions|
Written by Garry Robinson from GR-FX Pty Limited
Sometimes it is important to ensure that multiple queries have all run correctly together before you save the results. Microsoft Access allows you to do this through the use of transactions. Following is some example code that runs a number of different action queries using the transaction methodPrivate Sub cmdPostBatch_Click()
On Error GoTo errorTransaction
'Set up all the declarations and begin the transactions
Dim myWrk As
DAO.Workspace, myDbs As DAO.DATABASE, sqlStr As
sqlStr = "UPDATE PaymentPeriods SET
PaymentPeriods.runStatus = 'P' WHERE (((PaymentPeriods.paymentRunId)= " &
[Forms]![FX_Payments]![paymentRunId] & "))"
' Now all the action queries are
' Something happened so all the
queries are not committed
and look for the DB_FAILONERROR option to the execute method.
Try out our popular Access shareware Graf-FX