|
vb123.com
Garry Robinson's Popular MS Access, Office and VB
Resource Site
 |
|
Home
Contact Us
Order our Software
RSS &
Newsletter
Join our XML/RSS Newsfeed or sign up for our informative newsletter on
Office Automation, Access and VB topics
Read More
Get Good Help
If you need help with a database, our Professionals could be the answer
Read More
Is Your Database Corrupt ?
If you have a corrupt database,
Try our Access Recovery
service
The
Workbench
Find out who has your database open, start the
correct version of Access, easy compacting and backups, change startup
options, mde compile, shutdown database
Read and
Download
The Toolshed
Searchable help file comprising of all the information at vb123.com plus
hidden downloads etc. Read More
The Toolbox
Libraries of software that we regularly import into our projects.
Enhances the Toolshed More..
DryToast New
Backup and query your BaseCamp®
projects
Read More
Datamining/Graphs
Explore your data with this versatile graphing and data mining shareware
tool. Read More
Garry's Blog
Find out a few other things that
Garry has been writing about Microsoft Access.
Read more
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 Sydney,
Australia
Contact Us ...
Search ...
or try our new Expression Web
vb123.com.au
|
| |
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
mdlError.
Function
ErrorLog(strErrDesc As String, lngErrNum As Long, strWhereFrom As String) As
Boolean
On Error GoTo Err_ErrorLog
Dim strMsg As String
ErrorLog = True
strMsg = strMsg & "There has been an error in the application." & vbCrLf &
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 & "support@developersforhire.co.uk"
MsgBox strMsg, vbInformation, "Error Log."
Exit_ErrorLog:
Exit Function
Err_ErrorLog:
ErrorLog = False
MsgBox Err.Description, vbExcalmation, "Error detected."
Resume Exit_ErrorLog
End Function
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.
Err_SomeRoutine:
Call ErrorLog(Err.Description, Err.Number, Me.Name)
NOT
Err_SomeRoutine:
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
Rob Henderson
Developer from Aberdeen in Scotland
Download Files
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.
|