R
robert d via AccessMonster.com
I use unbound forms and DAO. I followed the recommendations of some others
and have come up with the following Exit Handler and Error Handler (this is
just an example; rstFlag states whether the recordset is open and bInTrans
states whether BeginTrans is turned on)
On Error GoTo Err_Ctrl
Dim wst As DAO.Workspace
Dim dbt As DAO.Database
Dim rst As DAO.Recordset
Exit_Sub:
If rstFlag = True Then
rst.Close
Set rst = Nothing
dbt.Close
Set dbt = Nothing
If bInTrans Then 'Rollback if the transaction is active.
wst.Rollback
End If
Set wst = Nothing
rstFlag = False
End If
DoCmd.SetWarnings True
Exit Sub
Err_Ctrl:
DoCmd.Hourglass False
errMsgStr = ""
ctrlfnctnm = "Save_Edit_Button"
'Call global error handler
Call BuyInfoForm_err(Err.Number, Err.Description, Err.Source, ctrlfnctnm,
errMsgStr)
Resume Exit_Sub
I recently added the transaction conditional statement in the exit handler.
I had a problem with the code where I began the transaction but then forgot
to commit or roll it back in the body of the code. When the code got to rst.
Close in the Exit handler, I got an error. Okay, I fixed the error, but
the problem with the error was that it created an infinite loop. The Exit
Handler error called the Error Handler which then tried to call the Exit
Handler which then called the Error Handler and so on.
I thought I was handling my Error Handling and Exit Handling correctly. But
I see now that if there is an error in the Exit Handler it creates an
infinite loop.
What am I doing wrong?
Thanks.
and have come up with the following Exit Handler and Error Handler (this is
just an example; rstFlag states whether the recordset is open and bInTrans
states whether BeginTrans is turned on)
On Error GoTo Err_Ctrl
Dim wst As DAO.Workspace
Dim dbt As DAO.Database
Dim rst As DAO.Recordset
Exit_Sub:
If rstFlag = True Then
rst.Close
Set rst = Nothing
dbt.Close
Set dbt = Nothing
If bInTrans Then 'Rollback if the transaction is active.
wst.Rollback
End If
Set wst = Nothing
rstFlag = False
End If
DoCmd.SetWarnings True
Exit Sub
Err_Ctrl:
DoCmd.Hourglass False
errMsgStr = ""
ctrlfnctnm = "Save_Edit_Button"
'Call global error handler
Call BuyInfoForm_err(Err.Number, Err.Description, Err.Source, ctrlfnctnm,
errMsgStr)
Resume Exit_Sub
I recently added the transaction conditional statement in the exit handler.
I had a problem with the code where I began the transaction but then forgot
to commit or roll it back in the body of the code. When the code got to rst.
Close in the Exit handler, I got an error. Okay, I fixed the error, but
the problem with the error was that it created an infinite loop. The Exit
Handler error called the Error Handler which then tried to call the Exit
Handler which then called the Error Handler and so on.
I thought I was handling my Error Handling and Exit Handling correctly. But
I see now that if there is an error in the Exit Handler it creates an
infinite loop.
What am I doing wrong?
Thanks.