Modify Default Error Messages?

  • Thread starter Thread starter Jennifer Crawford
  • Start date Start date
J

Jennifer Crawford

On my forms I have several subforms, which list the
records in 'table' format, with dividing lines, etc.

In these child tables, several fields are required. While
I have indicated which fields these are, occasionally the
user tries to enter a new record without completing the
previous one, and gets the inevitable error "Cannot allow
null value in <field name>". The problem is that this
confuses the heck out of users because field names are not
always as comprehensible as the much longer field labels
and all they see is that they received an error and
therefore the system must be broken.

Is there anyway to modify these error message so they show
something much more user friendly?
 
Unfortunately, the BeforeInsert event won't work (the
description of this event explains it: "The BeforeInsert
event occurs when the user types the first character in a
new record, but before the record is actually created").
Basically if I use that event it starts popping up error
messages the second I start typing in a new record. I want
it to flag the user if they *leave* the record uncompleted
(grin).

The Error event seems to be the best place to put it so
far - if I can just figure out how to only show my own
error message. Right now I see mine, followed by the
default Access message. Any on how to stop it so the
Access error message does not display?

BTW, while I do agree that defaults would be one way to
avoid this, our processes are to force the user to enter
data applicable to the record....which means defaults are
a no-no.
 
Took a bit of trial and error, but finally figured it out.

Private Sub Form_Error(DataErr As Integer, Response As
Integer)
If DataErr = 3314 Then
If IsNull(Me!MyField) Then
MsgBox "Missing Value!"
Me!MyField.SetFocus
Response = 0
Exit Sub
End If
End If
End Sub

The key is to set the Response to 0 - this prevents the
default error from appearing.
 
You need to set the response value in your code, so Access knows what to do.

...
Response = acDataErrContinue 'I've taken care of it keep going

Or

Response = acDataErrDisplay 'OK, display the built in error message.
 
I think you would need code in several events to trap the
error, then put up your own error messages. As a general
rule, if you can identify the event in which the error
arises and the error number, you can put code in the error
handler for that event to handle the error in whatever
manner that suits you, including ignoring it, with all the
consequences that might attend.


Kind regards,
David Gray
P6 Consulting
http://www.p6c.com/
 
Back
Top