Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tod Tod is offline
external usenet poster
 
Posts: 13
Default Proper way to pass errors up the line

Whenever I post these questions I wonder what it's going
to look like to a Google user five years from now. So:

"Hello from the past!"

Now here is my VBA newbie question o' the day:

How do I pass a raised error back to the procedure that
called?

Example (Don't laugh):

Sub FirstProc()
'Code Code Code
On Error Resume Next
Call Second
If Err.Number = vbObjectError + 513 Then
msgbox "This error came from SecondProc"
End if
'Code Code Code
End First

Sub SecondProc()
'Code Code Code
Err.Raise Number:=vbObjectError + 513, Description:="I
raised this error."
End Sub

This is obviously not correct, but hopefully you see what
I'm trying to do. I want SecondProc to pass my error back
to FirstProc and end without causing an error while in
SecondProc. Then when FirstProc gets the error it displays
a message or does something based on the err.number being
my raised error.

If I'm on the right track please show me where it's not
working. If I'm waaaay off please tell me how to do it.

tod


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Proper way to pass errors up the line

Tod,

One way, probably not the most elegant, that will work is to set up global
variables in the module called, say "GlblMyError" and "GlblErrDesc"
Before calling Second set these to 0 and ""

GlblMyError = 0
GlblErrDesc =""
In Second, if an error occurs, set GlblMyError = Error No. and GlblErrDesc
=Error description.

After returning from Second, check the value of GlblMyError

If GlblMyError =0 Then 'No error

'do the rest of your code

Else 'an error has occurred
Msgbox "An error has occurred in SecondProc. Error Code is " & GlblMyError *
"Description is " & GlblErrDesc

HTH
Henry


"Tod" wrote in message
...
Whenever I post these questions I wonder what it's going
to look like to a Google user five years from now. So:

"Hello from the past!"

Now here is my VBA newbie question o' the day:

How do I pass a raised error back to the procedure that
called?

Example (Don't laugh):

Sub FirstProc()
'Code Code Code
On Error Resume Next
Call Second
If Err.Number = vbObjectError + 513 Then
msgbox "This error came from SecondProc"
End if
'Code Code Code
End First

Sub SecondProc()
'Code Code Code
Err.Raise Number:=vbObjectError + 513, Description:="I
raised this error."
End Sub

This is obviously not correct, but hopefully you see what
I'm trying to do. I want SecondProc to pass my error back
to FirstProc and end without causing an error while in
SecondProc. Then when FirstProc gets the error it displays
a message or does something based on the err.number being
my raised error.

If I'm on the right track please show me where it's not
working. If I'm waaaay off please tell me how to do it.

tod




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Throwing Circular Errors When No Errors Exist MDW Excel Worksheet Functions 1 August 10th 06 02:15 PM
Pass The Formulas Please lsmft Excel Discussion (Misc queries) 3 February 13th 06 01:00 AM
How to: Pass Command Line Parameter ??? Webtest Excel Worksheet Functions 0 October 24th 05 05:27 PM
pass fail Tricia New Users to Excel 3 January 20th 05 03:45 PM
Unresolved Errors in IF Statements - Errors do not show in results Markthepain Excel Worksheet Functions 2 December 3rd 04 08:49 AM


All times are GMT +1. The time now is 02:56 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"