Solved

Debug

Posted on 1998-06-01
6
126 Views
Last Modified: 2013-11-25
I have problem using On Error statement
I have 2 method:
Public Sub MethodA()
      :
      :
      On Error Resume Next
      :
      Call MethodB
      :
End Sub

Private sub MethodB()
      :
End sub

The on error statement also triggered in MethodB. How to stop that?
0
Comment
Question by:Cruiser
  • 3
  • 3
6 Comments
 
LVL 4

Accepted Solution

by:
yowkee earned 50 total points
ID: 1462273
 If you didn't put any "On Error" statement in MethodB, it would just follow the error handler of caller function. That's why the on error resume next still make sense in MethodB.

  Just put the Error Handler for MethodB, then it won't follow error handler of MethodA.

Public Sub MethodA()
:
On Error Resume Next
:
Call MethodB
:
End Sub

Private sub MethodB()
On Error GoTo ErrHandler
:
Exit Sub
ErrHandler:
:
:
End sub

0
 

Author Comment

by:Cruiser
ID: 1462274
let said I do not want any error handling in method B, how to do that?
0
 
LVL 4

Expert Comment

by:yowkee
ID: 1462275
Cruiser,
 
  If you don't want any error handling in MethodB, just disable the error handler in MethodA before it call MethodB. But then any error in MethodB will handled by VB and may come out some unfriendly message to user.

Public Sub MethodA()
:
On Error Resume Next
:
On Error Goto 0  ' Disable error handler in this procedure
Call MethodB
On Error Resume Next  
:
End Sub


0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Cruiser
ID: 1462276
Thanks
One last Q, what is the 'range' of a On Error statement?
0
 
LVL 4

Expert Comment

by:yowkee
ID: 1462277
This is what stated in VB Help file:

---
On Error GoTo line
       Enables the error-handling routine that starts at line specified in the required line argument. The line argument is any line label or line number. If a run-time error occurs, control branches to line, making the error handler active. The specified line must be in the same procedure as the On Error statement; otherwise, a compile-time error occurs.

On Error Resume Next      
        Specifies that when a run-time error occurs, control goes to the statement immediately following the statement where the error occurred where execution continues. Use this form rather than On Error GoTo when accessing objects.
On Error GoTo 0      
        Disables any enabled error handler in the current procedure.

Remarks

If you don't use an On Error statement, any run-time error that occurs is fatal; that is, an error message is displayed and execution stops.
An "enabled" error handler is one that is turned on by an On Error statement; an "active" error handler is an enabled handler that is in the process of handling an error. If an error occurs while an error handler is active (between the occurrence of the error and a Resume, Exit Sub, Exit Function, or Exit Property statement), the current procedure's error handler can't handle the error. Control returns to the calling procedure. If the calling procedure has an enabled error handler, it is activated to handle the error. If the calling procedure's error handler is also active, control passes back through previous calling procedures until an enabled, but inactive, error handler is found. If no inactive, enabled error handler is found, the error is fatal at the point at which it actually occurred.

---
So, it depend which Error Handler is the current active Error Handler and which is enabled. If every procedure got on error statment, the range just within the procedure.
0
 

Author Comment

by:Cruiser
ID: 1462278
Thanks a lot
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now