Customizing System Messages.

  • Thread starter Thread starter Sameer
  • Start date Start date
S

Sameer

In my access project where i have set-up suitable relationships among
the tables, when an error occurs during data entry which violates the
relationship constraints, access displays a suitable message. It may be
like 'XXX databse doe not contain a related record.'
Can we customize this message so that it can more readable and does not
contain names of tables and will be more application specific and
general?
-Sameer
 
If you have designed forms, you can use the Error event of the form to catch
these engine-level messages and replace them with your own.
 
Allen

I've tried this but the error is not caught
Do you have a sample of this?

I would like to catch data integrity problem.

Thanks in advance
 
Here is a sample of a function to place in a standard module.

Then in the Form's Error event procedure:
Call FormError(Me, DataErr, Response)


Public Function FormError(frm As Form, DataErr As Integer, _
Response As Integer) As Integer
On Error GoTo Err_FormError
'Purpose: Generic Form_Error handler.
'Return: Response.
'Usage: In a form's Error event procedure:
' Call FormError(Me, DataErr, Response)
Dim strMsg As String
Const conDupeIndex As Integer = 3022
Const conFileMissing As Integer = 3024
Const conRelatedRecordRequired As Integer = 3201
Const conRequiredField As Integer = 3314
Const conInvalidType As Integer = 2113

Select Case DataErr
Case conDupeIndex
Response = acDataErrContinue
strMsg = "The record cannot be saved, as it would create a
duplicate."

Case conRelatedRecordRequired
Response = acDataErrDisplay

Case conRequiredField
strMsg = "This is a required field." & vbCrLf & vbCrLf & "Make an
entry, or press <Esc> to undo."
Response = acDataErrContinue

Case conInvalidType
strMsg = "Wrong type of data."
Response = acDataErrContinue

Case conFileMissing
strMsg = "Data file is currently unavailable."
Response = acDataErrDisplay

Case Else
Response = acDataErrDisplay
End Select

If Len(strMsg) > 0 Then
MsgBox strMsg, vbExclamation, "Invalid data"
End If
FormError = Response

Exit_FormError:
Exit Function

Err_FormError:
MsgBox "Error " & Err.Number & " - " & Err.Description
Resume Exit_FormError
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top