Exiting All Subs
Posted on 2005-03-31
I run into this problem quite often. Let's say that I call one sub from inside another and in the called sub I encounter a situation so that I want to exit all the subs (the called and the calling). If I do "Exit Sub" it only exits the called sub, not the sub doing the calling. The only way that I can think of to exit the calling sub is to turn some public boolean variable to false before I exit the called sub. That way when I test the variable in the calling sub and if has been turned to false exit that sub as well. Is there a statement that I can use from within the called sub that will exit not only itself but also whatever sub called it?
PS. I am by no means an expert programmer so please tell me how people that know what they're doing usually handle this situation. Should I be structuring my code differently? Should I always be making my tests in the main sub so that, if I do have to exit, I don't have to worry about exiting more than one sub?