J
jchauvin
I am having trouble getting my error handling to trap custom errors
generated by the Err.Raise command. My application is composed of user
forms and class modules without any standard modules. The Error
Trapping option is set to "Break on Unhandled Errors". My error
handling system is very simple and is designed to terminate the
application if any custom errors are detected. The error handler is
placed in the entry procedure with all custom errors within the various
forms or classes to be handled by this routine. Here is the code for
the entry procedure which is located in ThisWorkbook and called from
the Workbook_Open() Sub procedure:
Private Sub Workbook_Open()
Call OpenMainForm
End Sub
Public Sub OpenMainForm()
'
Dim frmMainForm As FMainForm
Set frmMainForm = New FMainForm
On Error GoTo ErrorTrap
Call frmMainForm.InitializeForm
frmMainForm.Show vbModal
Unload frmMainForm
Set frmMainForm = Nothing
Exit Sub
ErrorTrap:
MsgBox Err.Description, vbCritical, Err.Source
End Sub
Within the various user forms and class modules are validation checks
which raise errors if a problem is detected:
Err.Raise 1, "Sub HandleRunEditInfo", "Selection is not a valid
range."
Exit Sub
The expected behavior is for VBA to work up the Call Stack until it
encounters the error handler in the entry procedure located in
ThisWorkbook. Instead, VBA is displaying an unhandled error message.
There are no other error handlers (i.e. On Error statements) anywhere
within the forms or classes except for the entry procedure.
The unhandled error is being raise within the main form as a result of
a change in one of the controls but not being trapped by the error
handler contained in ThisWorkbook. I did try and move the above
routine to a standard module. This did not resolve the problem.
Any suggestion would be appreciated.
Thanks,
John C.
generated by the Err.Raise command. My application is composed of user
forms and class modules without any standard modules. The Error
Trapping option is set to "Break on Unhandled Errors". My error
handling system is very simple and is designed to terminate the
application if any custom errors are detected. The error handler is
placed in the entry procedure with all custom errors within the various
forms or classes to be handled by this routine. Here is the code for
the entry procedure which is located in ThisWorkbook and called from
the Workbook_Open() Sub procedure:
Private Sub Workbook_Open()
Call OpenMainForm
End Sub
Public Sub OpenMainForm()
'
Dim frmMainForm As FMainForm
Set frmMainForm = New FMainForm
On Error GoTo ErrorTrap
Call frmMainForm.InitializeForm
frmMainForm.Show vbModal
Unload frmMainForm
Set frmMainForm = Nothing
Exit Sub
ErrorTrap:
MsgBox Err.Description, vbCritical, Err.Source
End Sub
Within the various user forms and class modules are validation checks
which raise errors if a problem is detected:
Err.Raise 1, "Sub HandleRunEditInfo", "Selection is not a valid
range."
Exit Sub
The expected behavior is for VBA to work up the Call Stack until it
encounters the error handler in the entry procedure located in
ThisWorkbook. Instead, VBA is displaying an unhandled error message.
There are no other error handlers (i.e. On Error statements) anywhere
within the forms or classes except for the entry procedure.
The unhandled error is being raise within the main form as a result of
a change in one of the controls but not being trapped by the error
handler contained in ThisWorkbook. I did try and move the above
routine to a standard module. This did not resolve the problem.
Any suggestion would be appreciated.
Thanks,
John C.