Jump: Search:

Total Visual SourceBook

Total Visual SourceBook CD and Printed Manual

Microsoft Access 2007/2010 Version
is Shipping!

New features in Total Visual SourceBook for Access, Office 2007 and VB6

Supports Access/Office 2010 (32 bit), 2007, 2003, 2002, 2000, and
Visual Basic 6.0!

Also available for:
Access 97/95


View all FMS products for Microsoft AccessAll Our Microsoft Access Products

SourceBook Info:

Why SourceBook?

 

"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."

Van T. Dinh, Microsoft MVP

 

 

 

 

 
Royalty free source code library modules for Microsoft Access, VB6, VBA, OfficeRoyalty free source code library modules for Microsoft Access, VB6, VBA, OfficeVBA and VB6 Source Code Library Download the free trial version of Total Visual SourceBook for Microsoft Access, Office, VB6 and VBA
Category: General VBA/VB6 : Application Techniques
Description: Common application development code for messages boxes, error handling, and shutting down windows

Class: CVBAErrHandler

Global Error Handler for VBA.

This class provides a standardized error handling mechanism to trap errors, track the location and type of the errors, and to allow the programmer to take appropriate response. This version is VBA compatible--it contains no VB-specific code. If you want a VB-specific version, use the CErrHandler class available under Visual Basic, Application Techniques.

Procedure Name

Type

Description

(Declarations) Declarations Declarations and private variables for the CVBAErrHandler class
AppTitle Property Gets the current value of AppTitle
CurrentOperation Property Sets the name of the current operation. You can use this property to create logical checkpoints in your procedures. Before crucial sections of code, assign a unique value to the CurrentOperation property. If the error handler is triggered at any point after assigning this value, you will have a better idea of where the error occurred. This is especially helpful if you do not use line numbers in your code.
Destination Property Gets the current value of the Destination property. If you assigned an error log path name string to this property, a string is returned. If you assigned a Recordset object to this property, an object pointer to that recordset is returned.
DisplayMsgOnError Property Sets whether to show a message box with basic information about the error when an error is handled.
ErrorDescription Property Gets the description of the error that caused the error handler to be triggered (undefined until an error is handled by the HandleError method). Refer to this property in the AppSpecificErrorHandler procedure, or in the code triggered in response to the AfterHandlerCalled event.
ErrorLine Property Gets the line number of the procedure that caused the error when the error handler was triggered (undefined until an error is handled by the HandleError method). Refer to this property in the AppSpecificErrorHandler procedure, or in the code triggered in response to the AfterHandlerCalled event.
ErrorNumber Property Gets the error code that caused the error when the error handler is triggered (undefined until an error is handled by the HandleError method). Refer to this property in the AppSpecificErrorHandler procedure, or in the code triggered in response to the AfterHandlerCalled event.
IncludeExpandedInfo Property Returns whether additional information about the user's machine environment is included in the error log file
ProcName Property Gets the name of the procedure containing the error that triggered the error handler (undefined until an error is handled by the HandleError method). Refer to this property in the AppSpecificErrorHandler procedure, or in the code triggered in response to the AfterHandlerCalled event.
TraceExecution Property Sets whether to trace procedure execution (in addition to handling errors). If this property is true, a log file is maintained which tracks each procedure which is logged by the Push method. Even if no error occurs in the procedure, an entry is written. This information can be useful to trace the order in which procedures are called in your application. By default the information is stored in a file named "trace.log" in your application's directory.
AppSpecificErrHandler Private Custom error handling stub subroutine (perform a custom action here.) The recommended way to use the CVBAErrHandler class is to have it raise events into your program. You can receive the BeforeHandlerCalled and AfterHandlerCalled events. There you can provide specific functionality for your program, such as displaying a custom error message form, or closing the program cleanly. The advantage to using the events is that the CVBAErrHandler object can be completely generic. All custom app-specific logic is contained in your program, not in the class itself. If you cannot use the events however, because you are declaring the error handler object variable in a standard module, which cannot receive events, you can customize this procedure to provide app-specific error-handling logic. All app-specific logic should be confined to this procedure. That way when you incorporate the CVBAErrHandler class into your application, this is the only part of the code that will need to be modified.
Class_Initialize Initialize Set initial values to defaults which may be overridden with property settings
Class_Terminate Terminate Close trace log if opened, and check to be sure that all Push calls are balanced by Pop calls. If you raise an assertion at this point, double-check your code to see that you are calling the error handler correctly.
ClearLog Method Clear the error log (or table depending on the setting of the Destination property). If Destination is a string property indicating a DOS text file, this function simply deletes the file. If Destination is a Recordset object, this method deletes all rows from the recordset.
GetLastErr Private This method is called to get the last error that occurred. We increment the pointer as one of the last things done in Push() in order to add the next procedure to the next item available in the stack array. However, if an error occurred before we could add the next procedure to the stack, we need to go back to the previous item in the array to get the error that occurred.
HandleError Method Logs errors and responds to run-time errors. This is the main routine which handles a run-time error. It is responsible for displaying an error message, writing log information to a file, and raising events back into the caller program. This method is called if a run-time error branches to a section of code which calls this method. This method should only be called AFTER an error has occurred. First the current state of the error object is saved (error message, line, description). The BeforeHandlerCalled event is raised in the program which instantiated the error handler. The Cancel argument to BeforeHandlerCalled is tested. If the user does not cancel the error handler, by setting Cancel to True, the error handler proceeds to save error state information to the log file. After the error information has been saved, the AfterHandlerCalled event is raised to give the caller a chance to provide a custom response to the error, and the "AppSpecificHandler" private subroutine is called. If your program is not receiving the BeforeHandlerCalled or AfterHandlerCalled events, you can use this procedure to provide custom error handling, for example to display a custom form, or to provide the user a chance to exit the program
LogErrorToFile Private Logs the most recent error to a disk file. The name of the file is specified by setting the Destination property of the error handler object to a string containing the file name path
LogErrorToTable Private Logs the most recent error to a table. The table is specified by setting the Destination property of the error handler object to a recordset object which you create in your application
Pop Method Pops the current procedure name off the error handling stack. Call this method when your code successfully exits a procedure with no errors. It must be balanced by a call to the Push method when the procedure is first called.
Push Method Pushes the supplied procedure name onto the error handling stack. Call this method at the beginning of a procedure. It must be balanced by a call to the Pop method which is called when the procedure exits normally.

Overview of Total Visual SourceBook

The source code in Total Visual SourceBook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.

Additional Resources

Feedback

Contact Us  l   Web questions: Webmaster   l   Copyright © FMS, Inc., Vienna, Virginia
Celebrating our 26th Year of Software Excellence