Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Form Err.Raise error not trapped by entry procedure error handler

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 procedu

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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Form Err.Raise error not trapped by entry procedure error handler


wrote in message
oups.com...
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.


<....

Hi John,

The problem is this:

Write some code to show a form. Write some event code in the form and
include a breakpoint. Now execute it to the breakpoint. Now check the call
stack. See that line [<non-basic code]? That's VB's underlying plumbing
that shows forms by 'magic'. You can't raise COM errors through that. This
means that any errors raised in your forms can't be automatically trapped in
your calling code.

One solution to this is to have a central error-handling module that
includes all of your logic for dealing with both expected and unexpected
errors. Alternatively, you could raise a custom event in your form. Just
remember to declare the instances of your form(s) WithEvents.

HTH

Robert


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
Error trapped only while stepping through the code - Not triggered when run Jeff Excel Discussion (Misc queries) 7 March 7th 05 06:29 PM
Error trapped only while stepping through the code - Not triggered when run Jeff Excel Discussion (Misc queries) 0 February 28th 05 06:26 PM
Error not trapped - please help!!! Bura Tino Excel Programming 8 April 18th 04 09:27 PM
Can error 1004 be trapped???? Richard m Excel Programming 3 November 29th 03 02:55 PM
Raise Error from ActiveX dll to VBA Serge[_2_] Excel Programming 0 September 23rd 03 05:05 PM


All times are GMT +1. The time now is 08:54 PM.

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"