Call Procedure with On Error Statement

R

RyanH

Is there a way to call my error handler procedure when an error occurs in any
of my procedures. This is kinda what I was looking for.

Sub Test()

On Error GoTo ErrorHandler(Err.Number)
'my code here

End Sub

Sub ErrorHandler(ByVal intErrorNumber As Integer)

Select Case intErrorNumber
Case 1
'do this
'and so on

End Select

End Sub
 
J

Jim Thomlinson

The on error statement is leveraging goto which just takes you to a specific
section in the procedure... so you need something like this...

Sub Test()

On Error GoTo ErrorHandler
'my code here
Exit Sub
ErrorHandler:
call MyErrorHandler(Err.Number)
End Sub

Sub MyErrorHandler(ByVal intErrorNumber As Integer)

Select Case intErrorNumber
Case 1
'do this
'and so on

End Select

End Sub

***There is an automated addin that makes generating that code very easy.
Take a look at this link to get the addin. There are a bunch if indispensable
tools in this addin...
http://www.mztools.com/index.aspx
 
R

RyanH

thats what I figured I had to do. I wasn't sure if there is a way to call
the Error Handler Sub directly.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top