PC Review


Reply
Thread Tools Rate Thread

Call Procedure with On Error Statement

 
 
RyanH
Guest
Posts: n/a
 
      6th Oct 2008
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


--
Cheers,
Ryan
 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      6th Oct 2008
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
--
HTH...

Jim Thomlinson


"RyanH" wrote:

> 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
>
>
> --
> Cheers,
> Ryan

 
Reply With Quote
 
RyanH
Guest
Posts: n/a
 
      6th Oct 2008
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.
--
Cheers,
Ryan


"Jim Thomlinson" wrote:

> 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
> --
> HTH...
>
> Jim Thomlinson
>
>
> "RyanH" wrote:
>
> > 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
> >
> >
> > --
> > Cheers,
> > Ryan

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a Range variable to call a procedure with a ByVal statement... R Tanner Microsoft Excel Programming 14 18th Sep 2008 08:40 PM
Invalid procedure call error =?Utf-8?B?R2xhenVub3Y=?= Microsoft Access 12 23rd Nov 2005 08:21 PM
Remote procedure call error Balinder Windows XP General 2 1st Apr 2004 04:02 AM
Remote Procedure Call error dggoss@sbcglobal.net Windows XP General 3 4th Mar 2004 02:24 AM
Remote procedure call error Vincent Windows XP Networking 2 9th Oct 2003 04:14 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:07 PM.