Link to home
Create AccountLog in
Avatar of jhswinson
jhswinson

asked on

Access VBA Error Trapping

I have to add error trapping to a large Access application that was originally written with very little error trapping. All the examples that I have seen include the object name in the error trapping routine (See example 1) and the Access Wizards generate code with the object name included.

To save time I am thinking of using code without including the object name (See example 2) as it means that I only have to cut and paste it without editing the object name in the code. My question is is there are problems or disadvantages in  doing this ? I have tried it and it seems to work OK but I don't want to spend a lot of time applying this only to find that there is some future problem that I have not thought of.

Thanks

John


Example 1

Private Sub comOpenSearchForm_Click()
On Error GoTo Err_comOpenSearchForm_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmSearchUpdateMenu"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
 
Exit_comOpenSearchForm_Click:
    Exit Sub

Err_comOpenSearchForm_Click:
    MsgBox Err.Description
    Resume Exit_comOpenSearchForm_Click
End Sub

Example 2
Private Sub comOpenSearchForm_Click()
On Error GoTo Err_E1_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmSearchUpdateMenu"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
 
Exit_E1_Click:
    Exit Sub

Err_E1_Click:
    MsgBox Err.Description
    Resume Exit_E1_Click
End Sub
SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
For a number of my applications, I actually have a table (tbl_Errors) in the back-end database, and a separate code module that I pass info to from my in-line error handling.  

It records who encountered the error, the err.number, err.description, the active form, active control, and the name of the code module.

This does not "handle" the error, it simply records it for debugging purposes.
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account