Basic Error Handling Tool

Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScManaging Patner
Christopher Hankwembo is a Zambian Chartered Accountant and also developer of CA Premier Accounting Package
The best software application must always have an error handling tool


An error handler is a bit of code which will do pre-defined actions whenever an error occurs. For instance, produce a message to the user or designer describing the nature of the error. For an error handler to be useful, it must provide a minimum of information in its message to the user. Below is a typical example of an error handler I use.

Professional applications need to comprise error handling to trap unexpected errors. By using a consistent error handler, you can make sure that when bangs occur, the user is properly informed and your program exits elegantly. 

Basic error handling just hides the default behavior and exits the program. Advanced error handling can include all sorts of features such as saving information about the cause of the error and the environment at the time, attempts to address the problem, and information for the user on what they need to do next.

Basic Error Handling Code

Below is my simple error handling tool, please note that this is just a basic tool, only applies to novice developers, experts may have advanced error handlers and difficult to follow:

Private Sub Form_Error(DataErr As Integer, Response As Integer)
Select Case DataErr
Case 2107
MsgBox "The value you entered does not meet the validation rule defined for the field or control", vbOKOnly + vbExclamation, "Error Number 2107"
Response = acDataErrContinue
Case 2113
MsgBox "The value you entered isn't valid for this field", vbOKOnly + vbExclamation, "Error Number 2113"
Response = acDataErrContinue
Case 2169
MsgBox "You can't save this record at this time", vbOKOnly + vbExclamation, "Error Number 2169"
Response = acDataErrContinue
Case 2237
MsgBox "The text you entered isn't an item in the list", vbOKOnly + vbExclamation, "Error Number 2237"
Response = acDataErrContinue
Case 3022
MsgBox "The changes you requested to the table were not successful this may create duplicate", vbOKOnly + vbExclamation, "Error Number 3022"
Response = acDataErrContinue
Case 3200
MsgBox "The record cannot be deleted or changed because table includes related records", vbOKOnly + vbExclamation, "Error Number 3200"
Response = acDataErrContinue
Case 3201
MsgBox "You cannot add or change a record because a related record is required in the table", vbOKOnly + vbExclamation, "Error Number 3201"
Response = acDataErrContinue
Case 3314
MsgBox "Cannot perform cascading operation on table because it is currently in use", vbOKOnly + vbExclamation, "Error Number 3314"
Response = acDataErrContinue
Case 3315
MsgBox "Zero-length string is valid only in a Text or Memo field", vbOKOnly + vbExclamation, "Error Number 3315"
Response = acDataErrContinue
Case 3316
MsgBox "please contact the developer for this kind of error it could be a Corrupt download or incomplete installation ", vbOKOnly + vbExclamation, "Error Number 3316"
Response = acDataErrContinue
Case 2105
MsgBox "You can't go to the specified record you may be at the end of record set", vbOKOnly + vbExclamation, "Error Number 2105"
Response = acDataErrContinue
Case Else
MsgBox "This is an unexpected error occurred" & DataErr & "" & AccessError(DataErr)
Response = acDataErrContinue
End Select
End Sub


A good error handling tool is very important if developers are to deliver a more user-friendly software.

Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScManaging Patner
Christopher Hankwembo is a Zambian Chartered Accountant and also developer of CA Premier Accounting Package

Comments (1)

John TsioumprisIT Supervisor
Distinguished Expert 2020

Even at novice level since you have gathered so much error information it would be better if you had it stored in a table so that you could easily edit/update.
I really liked your Analog Clock on the form...

Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.