Generic Error Handling function (1 Viewer)

Status
Not open for further replies.

BarryMK

4 strings are enough
Local time
Today, 02:27
Joined
Oct 15, 2002
Messages
1,352
Generic error handling module - brilliant

Developed by Paul O'Flaherty to remove those arcane, baffling (to users) Access error messages.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' Standard Errors '

' ********************** '
' This module contains functions that catch inbuilt Access'
' errors and replaces them with user friendly error '
' descriptions. '


' Module : BasStandardErrors

' Revised : August 2004 - additional comments added

' Author : Paul O'Flaherty of Paul David Technologies Ltd www.pdtech.co.uk

' Conditions: This code is free to include and distribute in your applications

' on the condition that you include this commentry

' Usage

' Include the following code in all forms on the Form_Error event:

' Private Sub Form_Error(DataErr As Integer, Response As Integer)

' If StandardErrors(DataErr) = True Then Response = False

' End Sub

'

' In the error handler of all code include the following:

' If StandardErrors(Err) = False Then

' MsgBox Err & ": " & Err.Description

' End If

'

' Note that you can replace/add to the MsgBox line with handlers for

' more specific errors that the routine may generate.



Public Function StandardErrors(ByVal intErrorNumber As Integer, Optional blnShowUnknownError As Boolean) As Boolean

StandardErrors = True

Select Case intErrorNumber

Case 2105, 3314, 3316, 3101, 2046, 2169 'Cannot save current record

MsgBox "Cannot save this record." & "@Not all the required information for the current record has been entered." & "@Complete the remaining fields, or choose 'Undo' from the Edit menu " & "to cancel your changes before trying this action again.", vbExclamation

Case 2501 'Delete operation cancelled

MsgBox "Delete Cancelled." & "@The selected record(s) has not been deleted" & " @The operation was cancelled.", vbInformation


Case 3200 'Record has related data

MsgBox "This record could not be deleted." & "@The record could not be deleted because related information exists." & "@You must delete all related information before you can delete this record.", vbExclamation


Case 3022, 2115, 3399 'Duplicate data

MsgBox "Cannot add this record." & "@A record with the key details you have entered already exists, you cannot add duplicate data." & "@To continue, either modify the record, or press the Escape key to clear it.", vbExclamation
End Select
End Function

Public Function MsgBox(Prompt As String, Optional Buttons As Long = vbOKOnly, Optional Title As String = "Microsoft Access", Optional HelpFile As Variant, Optional Context As Variant) As Long


'This code produces a formatted error message box.

'The @ character should be used at the end of the title text and the description text.

'There must be two @ characters even if there is no description text

'The normal message box function in Access 97 supports use of the @ character to create

' formatted message boxes, but subsequant versions do not. Use this method even if you

' are developing for Access 97 to prevent problems when moving to later versions of Acess.


Dim strMsg As String


If IsMissing(HelpFile) Or IsMissing(Context) Then

strMsg = "MsgBox(" & Chr(34) & Prompt & Chr(34) & ", " & Buttons & ", " & Chr(34) & Title & Chr(34) & ")"

Else

strMsg = "MsgBox(" & Chr(34) & Prompt & Chr(34) & ", " & Buttons & ", " & Chr(34) & Title & Chr(34) & ", " & Chr(34) & HelpFile & Chr(34) & ", " & Context & ")"


End If

MsgBox = Eval(strMsg)

End Function
 
Status
Not open for further replies.

Users who are viewing this thread

Top Bottom