X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Closed TopicStart new topic
> Accgeneral Handling Errors In VBA, Access 97    
post Nov 20 2003, 11:59 AM

UdderAccess Admin + UA Ruler
Posts: 19,557
Joined: 27-April 02
From: Upper MI

Symptom: Unable to quickly locate where VBA error occurred

Subject: Handling VBA Errors

Applies to: Access 97, 2K, XP, 2K3 & 2K7

Author: Mark Davis - Date: February 4, 2004 - updated January 24, 2010

Keywords: VBA, Error, Error Handling

Overview: At some point in our journey to learn and master Access, we begin to generate our own VBA code and abandon the use of certain wizards. One of those will eventually be the VBA Code Wizard. Although it is a quick method of generating a procedural ‘shell’, it’s auto-generated error handling can be more robust when we more effectively mange any errors that may occur.

There is also a way to obtain the specific line of code where the error tookplace within the procedure. By simply adding a number in the first column of the line of code; it must be followed by at least one space. The line number will be picked up by the Access constant “erl”. It is suggested that when writing your code, begin your numbering sequence by 10’s or 5’s. That way, you’ll have room to squeeze in more code later. The “erl” is transferred to the”el” Global variable to prevent confusion of the first “erl” trapped, in the event of multiple errors. It is wise tostart with the first error encountered when mutiples occur.

Writing error handling routines for each and every procedure can be tedious. The code example(s) and demo app of this tutorial can provide a way to trap and manage unexpected errors. But then, what other kind of error is there?

A ‘global’ approach to error handling is the thrust of this discussion, where we will employ ‘global’ variables to assist in the management of the information collected during an error trapping process. We will also explore the primary Error Handling routine(s)/module in detail and how the ‘global’ variables play their part in passing a procedure’s error info to the primary routine.

Then, once the primary routine has been given a procedural call and error info, we will be able to present a user with an on-screen message, a text-based error file, append to a table and/or the ability to email the error to a developer and/or application administrator.

And, of course, we will demonstrate how to bring these Global Error Handling routines into your working Access application.

Files in the attached zip:
· Handling Errors in VBA.doc – Word
· ErrorHandler97.mdb – Access 97 (easily converts to 2K, XP, 2K3 & 2K7)
· ErrorHandler2007.accdb – Access 2007 (converted from ErrorHandler97.mdb, but not tested)
Attached File(s)
Attached File  ErrorHandlingTutorial07.zip ( 92.14K )Number of downloads: 56
Go to the top of the page

Custom Search

RSSSearch   Top   Lo-Fi    6th December 2019 - 09:18 PM