PC Review


Reply
Thread Tools Rate Thread

Can't "Call" Error Handler in Standard Module from Form Module

 
 
=?Utf-8?B?Sm9obiBE?=
Guest
Posts: n/a
 
      20th Apr 2007
I've followed 2 books exactly, as far as I can tell, but "it" doesn't work.

I have in a Standard Module [modBusinessLogic]:
_____________________________

' General Error Handler to be called from most procedures

Public Sub GenErrHand(lngErrNumber As Long, strErrDesc As String,
strModuleSource As String, strProcedureSource As String)

(I'd put the code in here, but this Sub isn't even being "called" - that's
the problem)

End Sub
_________________________

I have in a Form's Module [Form_FA1_OrgMaster_All]:
_________________________
Private Sub cboOrgs_AfterUpdate()

On Error GoTo HandleError

' Populates a combo box on the Financial Reports subform with reports titles
for the Org just chosen

(((NOTE: the first subform name below is purposefully misspelled -
not supposed to be ...FinRpt..., but rather ...FinRpts... - this sets up an
error to test Error Handler)))

Me.subfrmctrlFinRpt!cboIS_BySrv_List = Null
Me.subfrmctrlFinRpts!cboIS_BySrv_List.Requery

... More Code ...

Exit Sub

HandleError:
Dim strPrcdrName As String
strPrcdrName = "cboOrgs_AfterUpdate"
Dim strModName As String
strModName = Application.CurrentObjectName

GenErrHand Err.Number, Err.Description, strModName, strPrcdrName

Exit Sub

End Sub
_________________________
When I tested (with the Immediate Window) the Error Handler with a procedure
in the Standard Module that would create an error, it produced the Message
Box I want.

But when I test it with the set up above (chosing an Organization in the
Combo Box on the form), instead of getting the Message Box I want, I get
"Compile Error: Method or data member not found" - which is obviously the
regular VBA Message Box.

Why isn't my Error Handler being "called" correctly? Thanks

John D

 
Reply With Quote
 
 
 
 
Allen Browne
Guest
Posts: n/a
 
      20th Apr 2007
There could be another error in the module of that form.

1. Open the form's module in design view.

2. In the General Declarations (very top of the code), make sure you have
the line:
Option Explicit

3. Choose Compile on the Debug menu.
Fix any errors, and repeat until the code compiles without error.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"John D" <(E-Mail Removed)> wrote in message
news:927EEF40-5C70-459A-9240-(E-Mail Removed)...
> I've followed 2 books exactly, as far as I can tell, but "it" doesn't
> work.
>
> I have in a Standard Module [modBusinessLogic]:
> _____________________________
>
> ' General Error Handler to be called from most procedures
>
> Public Sub GenErrHand(lngErrNumber As Long, strErrDesc As String,
> strModuleSource As String, strProcedureSource As String)
>
> (I'd put the code in here, but this Sub isn't even being "called" -
> that's
> the problem)
>
> End Sub
> _________________________
>
> I have in a Form's Module [Form_FA1_OrgMaster_All]:
> _________________________
> Private Sub cboOrgs_AfterUpdate()
>
> On Error GoTo HandleError
>
> ' Populates a combo box on the Financial Reports subform with reports
> titles
> for the Org just chosen
>
> (((NOTE: the first subform name below is purposefully misspelled -
> not supposed to be ...FinRpt..., but rather ...FinRpts... - this sets up
> an
> error to test Error Handler)))
>
> Me.subfrmctrlFinRpt!cboIS_BySrv_List = Null
> Me.subfrmctrlFinRpts!cboIS_BySrv_List.Requery
>
> ... More Code ...
>
> Exit Sub
>
> HandleError:
> Dim strPrcdrName As String
> strPrcdrName = "cboOrgs_AfterUpdate"
> Dim strModName As String
> strModName = Application.CurrentObjectName
>
> GenErrHand Err.Number, Err.Description, strModName, strPrcdrName
>
> Exit Sub
>
> End Sub
> _________________________
> When I tested (with the Immediate Window) the Error Handler with a
> procedure
> in the Standard Module that would create an error, it produced the Message
> Box I want.
>
> But when I test it with the set up above (chosing an Organization in the
> Combo Box on the form), instead of getting the Message Box I want, I get
> "Compile Error: Method or data member not found" - which is obviously the
> regular VBA Message Box.
>
> Why isn't my Error Handler being "called" correctly? Thanks
>
> John D


 
Reply With Quote
 
=?Utf-8?B?Sm9obiBE?=
Guest
Posts: n/a
 
      20th Apr 2007
Allen

1) Option Explicit is in the General Declarations section of the Form's
Module.

2) I chose Compile on the Debug menu - fixed a couple of errors in OTHER
form modules. The db modules now all compile w/o error.

BUT - I still get the result I describe below.

Someone in another forum suggested I make sure that Tools/Options/General -
Error Trapping on the VBA Editor menu is set to "Break on Unhandled Errors" -
it is. Is that right? And, since I didn't even know about this Option - are
there other "settings" in either Access or VBA Editor that could cause this
problem?

Thanks - John D

 
Reply With Quote
 
Allen Browne
Guest
Posts: n/a
 
      20th Apr 2007
Try something like this:

Private Sub cboOrgs_AfterUpdate()
'On Error GoTo HandleError
Dim strPrcdrName As String
Dim strModName As String
strPrcdrName = "cboOrgs_AfterUpdate"
strModName = Application.CurrentObjectName

Debug.print Me.subfrmctrlFinRpt.ControlType
Debug.print Me.subfrmctrlFinRpt.Form!cboIS_BySrv_List

Exit_Handler:
Exit Sub

HandleError:
Stop
GenErrHand Err.Number, Err.Description, strModName, strPrcdrName
Resume Exit_Handler
End Sub

If the subform control is actually named subfrmctrlFinRpts (i.e. with a
trailing S), the code should not compile. Make sure the Name AutoCorrect
boxes are unchecked, and compact the database, and see if it still compiles.

If it compiles and runs okay, then you have something else on the form named
subfrmctrlFinRpt.

If it gives the error, you can remove the single quote from line 1, i.e.:
On Error GoTo HandleError

It should then go to the error handler. Press F8 to trace the code through
your error hander routine.

(BTW, I'm not sure Application.CurrentObjectName is a good idea. If the code
is called from another routine it may return the active form instead of the
form that actually has this code in its module.)

HTH.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"John D" <(E-Mail Removed)> wrote in message
news:927EEF40-5C70-459A-9240-(E-Mail Removed)...
> I've followed 2 books exactly, as far as I can tell, but "it" doesn't
> work.
>
> I have in a Standard Module [modBusinessLogic]:
> _____________________________
>
> ' General Error Handler to be called from most procedures
>
> Public Sub GenErrHand(lngErrNumber As Long, strErrDesc As String,
> strModuleSource As String, strProcedureSource As String)
>
> (I'd put the code in here, but this Sub isn't even being "called" -
> that's
> the problem)
>
> End Sub
> _________________________
>
> I have in a Form's Module [Form_FA1_OrgMaster_All]:
> _________________________
> Private Sub cboOrgs_AfterUpdate()
>
> On Error GoTo HandleError
>
> ' Populates a combo box on the Financial Reports subform with reports
> titles
> for the Org just chosen
>
> (((NOTE: the first subform name below is purposefully misspelled -
> not supposed to be ...FinRpt..., but rather ...FinRpts... - this sets up
> an
> error to test Error Handler)))
>
> Me.subfrmctrlFinRpt!cboIS_BySrv_List = Null
> Me.subfrmctrlFinRpts!cboIS_BySrv_List.Requery
>
> ... More Code ...
>
> Exit Sub
>
> HandleError:
> Dim strPrcdrName As String
> strPrcdrName = "cboOrgs_AfterUpdate"
> Dim strModName As String
> strModName = Application.CurrentObjectName
>
> GenErrHand Err.Number, Err.Description, strModName, strPrcdrName
>
> Exit Sub
>
> End Sub
> _________________________
> When I tested (with the Immediate Window) the Error Handler with a
> procedure
> in the Standard Module that would create an error, it produced the Message
> Box I want.
>
> But when I test it with the set up above (chosing an Organization in the
> Combo Box on the form), instead of getting the Message Box I want, I get
> "Compile Error: Method or data member not found" - which is obviously the
> regular VBA Message Box.
>
> Why isn't my Error Handler being "called" correctly? Thanks
>
> John D


 
Reply With Quote
 
=?Utf-8?B?Sm9obiBE?=
Guest
Posts: n/a
 
      21st Apr 2007
Ah - the internet. I just spent several hours wrestling with this issue -
wrote a response to your last post - hit send and BOOM - "Sorry - server's
too busy - too bad!". 30 minutes later - it hasn't shown up. Oh well.

1) Forgot to tell you I corrected the spelling of the subformcontrol before
I compiled.

2) I then changed spelling back to the "error" - it wouldn't compile.

3) I took the single quotation mark out thereby "activating" the On Error
line. When I chose a new organization in [cbo_Orgs] I still got the system
error message - not my custom message.

Someone just suggested to me that my problem is that my custom Error Handler
would only "work" at runtime, and the problem with the error I've set up is
that it produces a Compile error, not Runtime error.

The book I followed set up an error in passing variables to a function - not
a sub. The function divided a FirstNum by a SecondNum to produce a Result.
That code, along with the Error Handler that would be called from the
function if there were an error, compiled just fine. But when I passed the
arguments " 5,0 " to the function through the immediate window I got a Divide
By Zero error. At that point, the custom Error Handler intercepted the error
and displayed the "new custom" message.

So - could the problem be that I'm trying to force a custom Error Handler to
intercept a Compile Error when it can only work for Runtime Errors?

Thanks - John D
 
Reply With Quote
 
Allen Browne
Guest
Posts: n/a
 
      21st Apr 2007
Some errors (such as syntax errors) must be handled before the code can run.
The error handler cannot handle those.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"John D" <(E-Mail Removed)> wrote in message
news:5B5E438D-CAFE-41C3-9255-(E-Mail Removed)...
> Ah - the internet. I just spent several hours wrestling with this issue -
> wrote a response to your last post - hit send and BOOM - "Sorry - server's
> too busy - too bad!". 30 minutes later - it hasn't shown up. Oh well.
>
> 1) Forgot to tell you I corrected the spelling of the subformcontrol
> before
> I compiled.
>
> 2) I then changed spelling back to the "error" - it wouldn't compile.
>
> 3) I took the single quotation mark out thereby "activating" the On Error
> line. When I chose a new organization in [cbo_Orgs] I still got the system
> error message - not my custom message.
>
> Someone just suggested to me that my problem is that my custom Error
> Handler
> would only "work" at runtime, and the problem with the error I've set up
> is
> that it produces a Compile error, not Runtime error.
>
> The book I followed set up an error in passing variables to a function -
> not
> a sub. The function divided a FirstNum by a SecondNum to produce a Result.
> That code, along with the Error Handler that would be called from the
> function if there were an error, compiled just fine. But when I passed the
> arguments " 5,0 " to the function through the immediate window I got a
> Divide
> By Zero error. At that point, the custom Error Handler intercepted the
> error
> and displayed the "new custom" message.
>
> So - could the problem be that I'm trying to force a custom Error Handler
> to
> intercept a Compile Error when it can only work for Runtime Errors?
>
> Thanks - John D


 
Reply With Quote
 
=?Utf-8?B?Sm9obiBE?=
Guest
Posts: n/a
 
      21st Apr 2007

Allen - when you say "some errors (syntax errors) must be handled before the
code can run", I assume you mean that the hypothesis that a "custom error
handler" won't work with ANY compilation error - including misspelled object
names - is not correct. AND, that the problem I'm having is not because I'm
trying to make a "custom error handler" respond to a "compiler error"?

Thanks from the other side of the world - John D (Redwood Valley - CA) (USA)
 
Reply With Quote
 
Allen Browne
Guest
Posts: n/a
 
      21st Apr 2007
Correct: the custom error handler cannot handle compile errors.

If the code doesn't compile, it won't run, so it cannot go to the error
handler.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"John D" <(E-Mail Removed)> wrote in message
news:78A0EBE6-D7DF-41F6-8FDE-(E-Mail Removed)...
>
> Allen - when you say "some errors (syntax errors) must be handled before
> the
> code can run", I assume you mean that the hypothesis that a "custom error
> handler" won't work with ANY compilation error - including misspelled
> object
> names - is not correct. AND, that the problem I'm having is not because
> I'm
> trying to make a "custom error handler" respond to a "compiler error"?
>
> Thanks from the other side of the world - John D (Redwood Valley - CA)
> (USA)


 
Reply With Quote
 
=?Utf-8?B?Sm9obiBE?=
Guest
Posts: n/a
 
      21st Apr 2007
Oh ... :|

(Sound of almost-no-longer-beginner slapping himself up side the head!)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile error in hidden module: "Module Name" Eric Microsoft Excel Programming 4 5th Mar 2008 05:20 AM
DCOM error. The Diskeeper Module DkService.exe has reported the error "The remote procedure call failed and did not execute. Dave Onex Microsoft Windows 2000 0 29th Nov 2007 09:01 AM
Problem calling Error Handler in Standard Module from Form Module =?Utf-8?B?Sm9obiBE?= Microsoft Access Form Coding 2 19th Apr 2007 02:26 AM
adp module error at "0x77f58ddf" referenced memory at "0x32017800" =?Utf-8?B?TWF0dEw=?= Windows XP Help 1 11th May 2006 01:44 AM
how to get rid of "compile error in hidden module: <module name>" =?Utf-8?B?ZWxpZSBoYXJiICA8ZWRoLmFudEBob3RtYWlsLmNv Microsoft Word Document Management 1 18th Feb 2006 01:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:35 AM.