Background
Total Visual SourceBook is the most extensive professional source code library for Microsoft Access, Office, VBA, and Visual Basic 6.0.
How to initialize CErrorHandlerVBA Error Handler in a Standard Module
Total Visual SourceBook includes CErrorHandlerVBA as one of the error handling classes you can add to your project. Total Visual SourceBook options lets you set the class as your default error handler so that the other code your export from the code library have this error handler in place.
Information on the class, properties, and methods are on the CErrorHandlerVBA page, plus an example of how to use it in a form. Inside a form, you can initialize it with the WITHEVENTS option to create custom events to handle it.
Standard Modules
However, to use CErrorHandlerVBA across all your standard modules, it needs to be defined and initialized in a regular module. That was not shown in the example included in the product.
This is an example of a module and procedure that you can use to initialize the error handling class. Just call InitializeErrorHandling when your program starts to initialize the gclsErrorHandler variable:
Option Compare Database Option Explicit Public gclsErrorHandler As CErrorHandlerVBA Public Const gcfHandleErrors As Boolean = True Public Sub InitializeErrorHandling() ' Create the error handler object and set some of its optional properties Set gclsErrorHandler = New CErrorHandlerVBA With gclsErrorHandler .AppTitle = "My Application" .Destination = CurrentProject.Path & "\err.txt" .DisplayMsgOnError = True .IncludeExpandedInfo = True .CurrentOperation = "Initializing" ' Set to not overwrite the error log so you can see new errors appeneded to the end of the file .OverwriteLog = False ' Shows the error log to the user .ShowErrorFile = True End With End Sub
Initialization Hint
If your application doesn't run a global routine before it starts, you can check to see if the error handler exists and if not, initialize it before calling it like this:
If gclsErrorHandler Is Nothing Then
Call InitializeErrorHandling End If
Comments
0 comments
Please sign in to leave a comment.