-
Exiting outer subs
I have a sub, which calls a sub, which calls a sub (i.e. 3 levels). If an error occurs in the level 3 sub, the error handler exits the inside/level 3 sub, but the rest of the program continues....I want the entire thing to shut down, rather than just exiting the inside/level 3 sub, because the nature of the error requires the user to fix an excel file causing the error and run the entire thing again.
Is there a way for an inner sub to send a message to all outer subs to shut down after an error occurs in the inner sub, rather than continue running the outer sub(s)?
-
Do boolean functions instead and return false if an error occurs.
From sub 2
If Function3 = false then
MsgBox "Error occured in Function 3"
end if
-
create a public variable that the middle sub sets then check its value after the sub is called
like if the error happens
blnError = True
then after the code calling the sub
If blnError = True Then
Exit Sub
End If
set it to false later to make sure the value is reset for when it goes through those subs again
-
yup, dead easy.
create an error handler in Sub1,
and dont have an error handler in sub2 or sub3,
then sub1 will handle it...
error-handling is handles heiracally (i think that's the right word!)
-
Try using a global Boolean variable set it to True
If an error occurs set it to false
Then in each sub that calls another sub next line check the Bool if false exit this sub and so on.
-
-
Smack
Smack
Smack.
you gotta be faster then that Glen
;)
-
Declare a boolean as true or false in the level 2 and 3 subs before exiting them and check them in the level 1 and 2 subs....
GUUS
-
I know guess its my age:(
-
Snap
Snap
Snap
:D
damn it took me over half an hour to type that...
-
Thanks
I decided to go with the advice to eliminate error handling for the inner subs so that the error bubbled to the outside sub.
Since the application imports data from several linked excel files, my next dilemma was to capture the name of the excel file which the inner sub was acting upon when the error occured, so the user would know which excel file to fix/format correctly. To deal with that, I created a global variable (outside of all the subs) and set it to the name of the linked excel file it was trying to import at that moment from the inner sub which acted upon the excel file.
Thanks for all your help.
-
-
Why not use this file name variable for error checking
?
Set it to ""
If it gets a name in it then theres an error.
Save a little bit space