Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

Access 2007 VBA err handling not working

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
JP_TechGroup
Asked:
JP_TechGroup
  • 2
2 Solutions
 
Rey Obrero (Capricorn1)Commented:
try the setting

break on all errors

and, then

break on unhandled errors
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
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
 
JP_TechGroupAuthor Commented:
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
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:

  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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now