Results 1 to 5 of 5
  1. #1
    SemiAuto40 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    41

    Error 0 problem with error checking


    I'm now trying to add error handling to every procedure as suggested elsewhere on the internet... however when I use "On Error GoTo PROC_ERR" at the beginning of the procedure right after the variables are declared --- the error handler ALWAYS gets invoked because VBA always gives me Err.Number = 0, and therefore always bypasses my code to go straight to the error handler. What is the point of using On Error in a procedure if it is always going to trigger based upon an Access no error Err.Number of 0?

    It seems a waste of processor instructions to always go straight to the error handler with an On Error that always gets triggered and then try to engineer a way back to the code that you actually want to run.

    What am I missing?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Are you sure it's going straight to the error handler and not going through the code into the error handler? You need an exit handler with Exit Sub in it if you don't have that. Here's an example:

    http://www.baldyweb.com/ErrorTrap.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by SemiAuto40 View Post
    On Error GoTo PROC_ERR" at the beginning of the procedure right after the variables are declared --- the error handler ALWAYS gets invoked because VBA always gives me Err.Number = 0, and therefore always bypasses my code to go straight to the error handler.
    That makes absolutely no sense. More than likely there is a small piece of the puzzle that you're unaware of.

    Furthermore, vb procedures always have an error number assigned to the ERR object...but until a runtime error is actually encountered, it remains at 0. Subsequent errors simply change the error number that's assigned to that object. Getting back to err.number = 0 requires 1 of 2 things:

    1) err.clear (method)
    2) end of procedure

    if you really want to see what's happening, step through the procedure with F8.

  4. #4
    SemiAuto40 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    41
    I know what happened. Thanks to PBALDY I didn't have to take long to do the analysis. At first I did not have an EXIT_SUB procedure called from the PROCESS_ERROR sub, and that is where it got maddening. Then I stumbled upon the EXIT_SUB information after web search... however in the mean time I had included an Err.Number IF statement to troubleshoot and trap and keep the strange behavior of an Error number of 0 from seeming to call PROCESS_ERROR and Err.Number of 0 to my thinking was causing On Error going to PROCESS_ERROR. So that when I included the EXIT_SUB Resume statement at the bottom of PROCCESS_ERROR my "trap" kept showing me that my Err.Number was still the same "0" that I thought had been causing the trouble.
    I hope my explanation makes sense. The one thing that I do know is this: I would simply have to give up trying to use ACCESS and VBA if I didn't have total strangers willing to offer help like PBALDY and AJETRUMPET!

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Error checking field, SetFocus does not work
    By SemiAuto40 in forum Access
    Replies: 9
    Last Post: 07-26-2011, 10:08 AM
  2. Error Checking my Entry Result
    By AKQTS in forum Programming
    Replies: 3
    Last Post: 04-21-2011, 07:46 AM
  3. Error problem
    By Wayne311 in forum Programming
    Replies: 3
    Last Post: 02-21-2011, 05:21 PM
  4. Date error checking
    By oediaz in forum Programming
    Replies: 2
    Last Post: 03-26-2010, 12:08 PM
  5. Problem with vba error
    By lukusm in forum Programming
    Replies: 3
    Last Post: 01-25-2010, 07:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums