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
356 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) 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 58
ID: 36475162

 Either will work.

Jim.
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 58
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 58

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

726 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