J
Jim Franklin
Hi,
I have tried using a transaction to make sure that changes to a number of
tables are completed successfully, or all rolled back. However, I cannot get
the transaction to rollback, and the changes are applied regardless.
My test code below deletes all the records from a series of tables. Even
when I select No at the end, all my tables end up empty!
Any help is very much appreciated!
Cheers,
Jim
'set workspace for transaction
Set wrkDefault = DBEngine.Workspaces(0)
MyArray(0) = "tbl_Users"
MyArray(1) = "tbl_Applicants"
MyArray(2) = "tbl_Cases"
MyArray(3) = "tbl_CaseApplicants"
MyArray(4) = "tbl_Cases_Notes"
MyArray(5) = "tbl_Documents"
MyArray(6) = "tbl_Providers"
MyArray(7) = "tbl_ProviderNotes"
MyArray(8) = "tbl_ProviderContacts"
MyArray(9) = "tbl_Solicitors"
MyArray(10) = "tbl_ASU"
MyArray(11) = "tbl_BuildingsContents"
MyArray(12) = "tbl_FIB"
MyArray(13) = "tbl_Investments"
MyArray(14) = "tbl_Life"
MyArray(15) = "tbl_Mortgages"
MyArray(16) = "tbl_PHI"
wrkDefault.BeginTrans
DoCmd.SetWarnings False
'Delete records
For i = 16 To 0 Step -1
strSQL = "Delete * FROM " & MyArray(i) & " WHERE [AgentCode] = '" &
strImportAgentCode & "';"
DoCmd.RunSQL strSQL
Next i
DoCmd.SetWarnings True
If MsgBox("Save all changes?", vbYesNo) = vbYes Then
wrkDefault.CommitTrans
Else
wrkDefault.Rollback
End If
I have tried using a transaction to make sure that changes to a number of
tables are completed successfully, or all rolled back. However, I cannot get
the transaction to rollback, and the changes are applied regardless.
My test code below deletes all the records from a series of tables. Even
when I select No at the end, all my tables end up empty!
Any help is very much appreciated!
Cheers,
Jim
'set workspace for transaction
Set wrkDefault = DBEngine.Workspaces(0)
MyArray(0) = "tbl_Users"
MyArray(1) = "tbl_Applicants"
MyArray(2) = "tbl_Cases"
MyArray(3) = "tbl_CaseApplicants"
MyArray(4) = "tbl_Cases_Notes"
MyArray(5) = "tbl_Documents"
MyArray(6) = "tbl_Providers"
MyArray(7) = "tbl_ProviderNotes"
MyArray(8) = "tbl_ProviderContacts"
MyArray(9) = "tbl_Solicitors"
MyArray(10) = "tbl_ASU"
MyArray(11) = "tbl_BuildingsContents"
MyArray(12) = "tbl_FIB"
MyArray(13) = "tbl_Investments"
MyArray(14) = "tbl_Life"
MyArray(15) = "tbl_Mortgages"
MyArray(16) = "tbl_PHI"
wrkDefault.BeginTrans
DoCmd.SetWarnings False
'Delete records
For i = 16 To 0 Step -1
strSQL = "Delete * FROM " & MyArray(i) & " WHERE [AgentCode] = '" &
strImportAgentCode & "';"
DoCmd.RunSQL strSQL
Next i
DoCmd.SetWarnings True
If MsgBox("Save all changes?", vbYesNo) = vbYes Then
wrkDefault.CommitTrans
Else
wrkDefault.Rollback
End If