Solved

Debug

Posted on 1998-06-01
6
129 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 Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

856 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