T
Tony Vrolyk
I have a subroutine on a form that is using transactions to undo changes if
there is an error. The rollback is done in the error handling at the end of
the subroutine . However in the body of the subroutine I am using some DAO
to delete a record and it is quite possible and expected that it will fail
on occasion because of related records in other tables. If that is the case
I want it to fail to preserve the record.
My question is this. How do I handle the delete error and continue without
causing the subroutine error handling to fire and therefore rollback the
procedure yet still allow it to fire when other errors occur.
Sample below
Thanks
Tony Vrolyk
'**********sample***********
Private Sub cmdSaveAndDelete_Click()
On Error GoTo HandleErr
Dim wrkDefault As Workspace
Dim rst As DAO.Recordset
Set wrkDefault = DBEngine.Workspaces(0)
wrkDefault.BeginTrans
'Delete Participant record
Set rst = CurrentDb().OpenRecordset("Participants", dbOpenDynaset)
rst.FindFirst "[SSN] ='" & Me.OpenArgs & "'"
If Not rst.NoMatch Then
rst.Delete
End If
rst.Close
'some more DAO
'even more DAO
Set rst = Nothing
wrkDefault.CommitTrans
ExitHere:
Exit Sub
HandleErr:
wrkDefault.Rollback
Select Case Err.Number
Case Else
MsgBox "Error " & Err.Number & vbCr & Err.Description,
vbCritical, "Form_Participants_CorrectSocial.cmdSaveNew_Click"
End Select
Resume ExitHere
End Sub
'*******************
there is an error. The rollback is done in the error handling at the end of
the subroutine . However in the body of the subroutine I am using some DAO
to delete a record and it is quite possible and expected that it will fail
on occasion because of related records in other tables. If that is the case
I want it to fail to preserve the record.
My question is this. How do I handle the delete error and continue without
causing the subroutine error handling to fire and therefore rollback the
procedure yet still allow it to fire when other errors occur.
Sample below
Thanks
Tony Vrolyk
'**********sample***********
Private Sub cmdSaveAndDelete_Click()
On Error GoTo HandleErr
Dim wrkDefault As Workspace
Dim rst As DAO.Recordset
Set wrkDefault = DBEngine.Workspaces(0)
wrkDefault.BeginTrans
'Delete Participant record
Set rst = CurrentDb().OpenRecordset("Participants", dbOpenDynaset)
rst.FindFirst "[SSN] ='" & Me.OpenArgs & "'"
If Not rst.NoMatch Then
rst.Delete
End If
rst.Close
'some more DAO
'even more DAO
Set rst = Nothing
wrkDefault.CommitTrans
ExitHere:
Exit Sub
HandleErr:
wrkDefault.Rollback
Select Case Err.Number
Case Else
MsgBox "Error " & Err.Number & vbCr & Err.Description,
vbCritical, "Form_Participants_CorrectSocial.cmdSaveNew_Click"
End Select
Resume ExitHere
End Sub
'*******************