Garry Robinson's Popular MS Access, Office and VB
The Magazine that Access Developers loved to read and write for is back
Article Index Here or
Join our XML/RSS Newsfeed or sign up for our informative newsletter on
Office Automation, Access and VB topics
Sign up here
Get Good Help
If you need help with a database, our Australian Professionals could be
Find out who has
your database open, start the correct version of Access, easy compacting
and zip backups, change startup options, compile, shutdown
Access > SqlServer
Upsize to SQL Server 2005 or 2008, easily repeated conversions,
highly accurate SQL query
translation and web form conversion.
Like FMS Products?
Purchase them from us and get a free Workbench or Smart Access
Libraries of software that we regularly import into our projects.
Find out a few other things that
Garry has been writing about Microsoft Access.
About The Editor Garry
Robinson writes for a number of popular computer magazines, is now a
book author and has worked on 100+ Access databases. He is based in
Contact Us ...
An Access Global Error Handler
By Rob Henderson
Most VBA programmers tend to stick with the
local flavour of error reporting within their applications. By using a global
error handler you can achieve the following;
1. You can introduce new parameters for any error trapped. I.e. Where was the
error called from frmMain, frmContact, etc. This can be particularly helpful
when debugging errors in multiple function chain calls.
2. You can introduce database logging once in the function, whereas your only
other option is to include in any error trap locally.
3. The learning curve of your applications is slighter for any other developer.
I.e. All the error code is in one place.
4. Your users will see the same formatted message type each time your
application encounters a problem.
5. You can include a point of contact such as an email address.
To use this technique, place the following function in a new module called
ErrorLog(strErrDesc As String, lngErrNum As Long, strWhereFrom As String) As
On Error GoTo Err_ErrorLog
Dim strMsg As String
ErrorLog = True
strMsg = strMsg & "There has been an error in the application." & vbCrLf &
strMsg = strMsg & "Error Number: " & lngErrNum & vbCrLf
strMsg = strMsg & "Error Description: " & strErrDesc & vbCrLf
strMsg = strMsg & "Error Location: " & strWhereFrom & vbCrLf
strMsg = strMsg & "Please note the above information when contacting Support." &
vbCrLf & vbCrLf
strMsg = strMsg & "email@example.com"
MsgBox strMsg, vbInformation, "Error Log."
ErrorLog = False
MsgBox Err.Description, vbExcalmation, "Error detected."
Use the following code to call the ErrorLog…
Within a sub or function, place the call to error log where you would normally
place your error code. I.e.
Call ErrorLog(Err.Description, Err.Number, Me.Name)
MsgBox Err.Description, Err.Number, "Error"
The last argument is where the error code is sitting. In the above example we
are passing the name of the form we are currently executing the code from.
You could improve the functionality of the above function by introducing logging
to a database table. We have included this functionality within the download
Developer from Aberdeen in Scotland
Click here for the
Access 2000 download file
Other Pages On This Site You Might Like To Read
Track all changes made
to a record in Microsoft Access
Access 2002 (XP)
Trappable Errors Numbers And Descriptions
Replace Your File API’s With
The FileDialog Object
Click on the following button
to jump to the next page in the document loop.