vb123.com

Garry Robinson's Popular MS Access, Office and VB Resource Site

 

Home  Contact Us

Order Software

Search vb123

 Smart Access  
The Magazine that Access Developers loved to read and write for is back
Article Index Here or
Purchase Here

RSS & Newsletter  
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 the answer
Read More

  The Workbench  Find out who has your database open, start the correct version of Access, easy compacting and zip backups, change startup options,  compile, shutdown database
Read and Download


Access > SqlServer 
Upsize to SQL Server 2005 or 2008, easily repeated conversions, highly accurate SQL query
translation and web form conversion.
Read More

Like FMS Products?
Purchase them from us and get a free Workbench or Smart Access  More

The Toolbox
Libraries of software that we regularly import into our projects.  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 ...


 

 

Next Tip  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 Next Tip to jump to the next page in the document loop.

 

Links >>>  Home | Search | Workbench | Orders | Newsletter | Access Security | Access professionals