Solved

Access 2007 VBA err handling not working

Posted on 2011-02-17
4
245 Views
Last Modified: 2012-05-11
I am building my error catching routines on a new dbase and the error handling does not seem to work in any case. I have my error handling set to BREAK IN CLASS MODE.
Code is standard error handling as below.

The code breaks and displays the error popup.

Public sub some_action()
on Error goto errhandler

 ' some code
exit sub
errhandler:
Resume err1
err1:
'some action that logs the error and returns user to 'beginning of program

End Sub

Open in new window

0
Comment
Question by:JP_TechGroup
  • 2
4 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 250 total points
ID: 34917337
try the setting

break on all errors

and, then

break on unhandled errors
0
 
LVL 57

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 250 total points
ID: 34917526
Besides the setting (which is your main problem), you also want a change in structure a bit:

Public sub some_action()
  on Error goto errhandler

   ' some code
Exit_some_Action
   ' Do cleanup
   exit sub

errhandler:
     'some action that logs the error or handles the error
     Resume Exit_some_Action
or
     Resume Next
or
     Resume

End Sub
0
 

Author Comment

by:JP_TechGroup
ID: 34919733
JD, the code example uses:
exit sub
errhandler:
Resume err1
err1:
'action to take
end sub

Is there some reason why the label "err1" should be in the sub before the exit? I've tried it and it makes no difference that I can see.
Also, I have tried all three options (though usually I use break on unhandled errors) with the same result.
Further experimentation shows that this does catch some errors, but not others....
0
 
LVL 57
ID: 34920192

  One should only Resume after the error has been handled, not before.  And you don't want to exit without issuing a resume of some type as you leave the error handler active then.

JimD.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

911 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

18 Experts available now in Live!

Get 1:1 Help Now