Chapter 26: Bulletproofing Access Applications
921
The logging information you add to a database might include updating a time stamp on records in
a table when changes are made. Be aware, however, that the more logging you do, the slower the
application becomes. The log information will cause the database to grow as well, unless the log
information is stored in another location.
You can even tailor the level of logging to suit individual users or groups of users. Using the infor-
mation captured on a login form, the application can determine at start-up what level of logging to
impose during the session. To make reviewing the logs much easier, you can even log to a table
located in an external database in a different location on the network.
Usage logs can also provide an excellent way to perform a postmortem on an application that
doesn’t operate properly. If you have logging in each subroutine and function that might fail at
runtime, you can see exactly what happened at the time an error occurred, instead of relying on
the user’s description of the error.
Logging can produce undesirable results when errors occur. For example, an error that causes an
endless loop can easily consume all available disk space on the user’s computer if each iteration of
the loop adds a message to an error log. Use logging wisely. You may want to add logging to every
procedure in an application during the beta-test process, and reduce the number of calls to the log-
ging procedure just before distributing the application to its users. You may even provide some
way that users can turn on logging if they encounter a reproducible problem in a database
application.
You can easily activate or deactivate the calls to logging before distributing the application to users
using the compiler directives described in Chapter 10. For example, the following call to the
Logger() function will be ignored if the DEVELOPMENT constant has not been defined in the
application.
#If DEVELOPMENT Then
Logger(“Begin function TestuserInput() “, Now())
#End If
During the development cycle, include the following statement in the Declarations section of the
form module, and calls to Logger() will be enabled. Before compiling and distributing to the
user, either comment out this statement or set the DEVELOPMENT constant to 0.
#Const DEVELOPMENT = 1
The function shown in the following listing provides an elementary form of error logging.
LogError() writes the following information to a table named tblErrorLog:
l (^) The current date and time
l The procedure name that produced the error
l (^) The error number
l The error description
l (^) The form that was active at the time the error occurred (may be null if no form is open)