Solved

Does err = 0 and err.Clear do the same thing?  Which one clears the error from the stack?

Posted on 2011-09-02
8
355 Views
Last Modified: 2012-05-12
Within Microsoft Access VBA, if I want to remove an error completely from memory do I use Err = 0 or Err.Clear?

0
Comment
Question by:stephenlecomptejr
8 Comments
 
LVL 14

Accepted Solution

by:
athomsfere earned 167 total points
ID: 36475101
error 0 in most things (and Access as well) means success. So Err=0 means the action was successful. Err clear clears any level error including a success level error.

So no, they are not the same.
0
 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Access MVP)
DatabaseMX (Joe Anderson - Access MVP) earned 166 total points
ID: 36475113
Answer is No.

Err=0 as in

If Err.Number = 0 means No Error occurred.

From the Help File:
Clear Method
         

Clears all property settings of the Err object.

Syntax

object.Clear

The object is always the Err object.

Remarks

Use Clear to explicitly clear the Err object after an error has been handled, for example, when you use deferred error handling with On Error Resume Next. The Clear method is called automatically whenever any of the following statements is executed:

Any type of Resume statement
Exit Sub, Exit Function, Exit Property

===

On Error Goto 0   resets any error currently in effect.

mx


Any On Error statement
Note   The On Error Resume Next construct may be preferable to On Error GoTo when handling errors generated during access to other objects. Checking Err after each interaction with an object removes ambiguity about which object was accessed by the code. You can be sure which object placed the error code in Err.Number, as well as which object originally generated the error (the object specified in Err.Source).
0
 
LVL 57
ID: 36475162

 Either will work.

Jim.
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 57
ID: 36475211
 I just tested this and either will work, but err.clear is better.  

  Doing:

  Err = 0

  Doesn't clear the error object (ie. the last error description still remains).  However it will work as you would think for in-line error handling. i.e.

  On Error Resume Next
  Err = 0
  ' Do something
  If Err<>0 then
    ' Error occured
  End If

Jim.
0
 
LVL 75
ID: 36475226
"  Doesn't clear the error object (ie. "
Then they are not the same.

"Use Clear to explicitly clear the Err object after an error has been handled, "

mx
0
 
LVL 57

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 167 total points
ID: 36475299
 I don't think though that was the intent of the question.   Also you can't be positive that Err = 0 doesn't clear the stack.  Remember, doing Err = 0 has been around a lot longer then Err.Clear.  The error object wasn't introduced until Access 95 when VBA came along, so it's hard to say what Err = 0 actually does.  It doesn't clear the error object for sure, but I'm not sure about the stack.

 Wayne would know the answer to that for sure.

Jim.

 
0
 
LVL 75
ID: 36475331
"so it's hard to say what Err = 0 actually does. "
Which is why I don't use it in this context.

Stephen ... if you want the ultimate error handler, then see this:

http://www.everythingaccess.com/vbwatchdog.htm

And lots of great info in this site ...

mx
0
 
LVL 1

Author Comment

by:stephenlecomptejr
ID: 36488597
Thanks for all the great replies!
I appreciate the comments.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

809 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