VBA main error handling not working for called userform

Viewed 24

I have a main sub, which does some stuff and then calls a userform. The main sub has error handling. Errors in the subroutine seem to be also handled by the main sub, but errors in the userform not.

My main sub looks like this:

Sub mainSub()
On Error GoTo errorProcedure
    
     'do some stuff
     call subroutine
     userform1.show
     Exit Sub

errorProcedure:
msg = "Error " & Str(Err.Number) & Chr(13) & Err.description
MsgBox msg, , "Error", Err.HelpFile, Err.HelpContext
Err.Clear
End

End Sub

So whenever any error occures within the main sub or in the called subroutine, it is handled within the main sub error handling. But after it shows the userform, I think it ends the main sub and every error that occures within the userform still throws an ugly error taking the user to the VBA code. Of course I could add error handling in every sub in the userform but there are a lot and I feel like it could be done with the error handling from the main sub. Am I correct?

0 Answers
Related