Is it possible to change Access error messages ?

  • Thread starter Thread starter randria
  • Start date Start date
R

randria

Hello,
I would like to know if one can change an error message of access, Example
Error #3314 , I want to add " Enter a value or 0 in this field ".

If it is not possible how can I disable this message so that I can try to
replace it.

Many thanks.
 
You can't change an error message, but you can intercept it and display your
own message by putting in error trapping.

Allen Browne has an introduction to the topic at
http://www.allenbrowne.com/ser-23a.html

You'd want something like the following as a replacement for lines 7 and 8
in his sample:

Select Case Err.Number
Case 3314
MsgBox "Enter a value or 0 in this field."
Case Else
Msgbox Err.Number & Err.Description
End Select
Resume Exit_SomeName
 
Yes, error handling is an important part of creating polished applications.
There are many techniques for doing so, some quite sophisticated, some
pretty straightforward.

What you are seeing is a form error , so the error handling needs to go in
the form's error event.

A simple one might look something like this:

Private Sub Form_Error(DataErr As Integer, Response As Integer)
Select Case DataErr
Case 3314
MsgBox "That isn't a valid entry." & vbCrLf & "Enter a value or 0
in this field.", vbInformation + vbOKOnly, "Invalid Entry"
Case Else
End Select
Response = True
Screen.ActiveControl.Undo
End Sub

I use Case statements in many form error handlers because it is often
necessary to respond to more than one type of error and having the Select
Case structure in place makes it easier to add additional cases. Here, of
course, a simple If statement would be fine.
 
You can also make zero the default value of the control so the error happens
less often.
Jill
 
Thank you Doug, it works.
cheers.

Douglas J. Steele said:
You can't change an error message, but you can intercept it and display your
own message by putting in error trapping.

Allen Browne has an introduction to the topic at
http://www.allenbrowne.com/ser-23a.html

You'd want something like the following as a replacement for lines 7 and 8
in his sample:

Select Case Err.Number
Case 3314
MsgBox "Enter a value or 0 in this field."
Case Else
Msgbox Err.Number & Err.Description
End Select
Resume Exit_SomeName
 
Back
Top