SyntaxSocialist
Registered User.
- Local time
- Today, 00:20
- Joined
- Apr 18, 2013
- Messages
- 109
Hey all. Just wrapping up my first access programming project and am integrating some error handling code. Never worked with it before. Found this and this very helpful in getting me started.
Question: I'm trying to sort out how to put multiple error handlers in one procedure. For example, I might want "On Error GoTo ErrHandler1" to encompass half of a procedure so that any error in that half will display a MsgBox and then Resume Next, but then want "On Error GoTo ErrHandler2" to encompass the other half and to display a different MsgBox before exiting the procedure. Do I need to tell the code to ignore the previous GoTo statement in order for it to recognize the next one?
From my internet searches I've gleaned that maybe all I need to do is something like the following. I'd love some feedback on whether I'm way off or on the right track.
Any additional tips/tricks/resources you'd like to point me towards would be appreciated as always
Question: I'm trying to sort out how to put multiple error handlers in one procedure. For example, I might want "On Error GoTo ErrHandler1" to encompass half of a procedure so that any error in that half will display a MsgBox and then Resume Next, but then want "On Error GoTo ErrHandler2" to encompass the other half and to display a different MsgBox before exiting the procedure. Do I need to tell the code to ignore the previous GoTo statement in order for it to recognize the next one?
From my internet searches I've gleaned that maybe all I need to do is something like the following. I'd love some feedback on whether I'm way off or on the right track.
Code:
Private Sub DoesStuff()
On Error GoTo ErrHandler1:
'Code that might produce an error
On Error GoTo ErrHandler2:
'Code that might produce a different error
Exit Sub
ErrHandler1:
'Code that displays a MsgBox with error information
Resume Next
ErrHandler2:
'Code that displays a different MsgBox with error information
Exit Sub
End Sub
Any additional tips/tricks/resources you'd like to point me towards would be appreciated as always