Replacing Access error messages

  • Thread starter Thread starter Amir
  • Start date Start date
A

Amir

Hi!

How can I trap the error message: "The field ... cannot contain a null value
because the Required property for this field is set to
..True. Enter a value in this field"? I want to replace it with other
message.

Thanks for you help!,
Amir.
 
Hi!

How can I trap the error message: "The field ... cannot contain a null value
because the Required property for this field is set to
.True. Enter a value in this field"? I want to replace it with other
message.

Thanks for you help!,
Amir.

Here's how you can find the correct error and show your own message
for any of the form level errors.

First code the Form's Error event:

MsgBox "Error#: " & DataErr ' Display the error number
Response = acDataErrDisplay ' Display Default message

Then open the form and intentionally make that error.

The message box will display the error number and the default error
message.

Next, go back to the error event and change that code to:

If DataErr = XXXX Then
Response = acDataErrContinue ' Don't display the default message
MsgBox "Please enter data in all required fields."
Else
MsgBox "Error#: " & DataErr
Response = acDataErrDisplay ' Display Default message
End If

where XXXX is the error number.
 
Hi there!
The problem is sometimes I don't know which event made that error.
I mean, If I'm in a new record, for example, and I am in the last field and
pressing "tab",
I'll get an error message, but how can I know in which event to put the
error handler?
Same thing goes for losing focus to subform when editing a record,
and for the error i've written here.

I've tried trapping these errors in the events I could think of,
but still these are not the correct events.
Can I trap them without knowing what's the event that's causing them?
How can I know which event is causing an error which does not
already have "exposed" VB code?

Regards,
Amir.
 
Hi there!
The problem is sometimes I don't know which event made that error.
I mean, If I'm in a new record, for example, and I am in the last field and
pressing "tab",
I'll get an error message, but how can I know in which event to put the
error handler?
Same thing goes for losing focus to subform when editing a record,
and for the error i've written here.

I've tried trapping these errors in the events I could think of,
but still these are not the correct events.
Can I trap them without knowing what's the event that's causing them?
How can I know which event is causing an error which does not
already have "exposed" VB code?

Regards,
Amir.
You asked how to give your own message in place of the default Access
message for a missing Required Field. This is a Form level error.
You don't have to know which control is causing this kind of problem.
First code the Form's Error event: <

The code goes in the FORM's Error event, not in any one particular
control event.
If you would like to include the errant control's name in the message
for the user, you can use:
MsgBox "Please enter data in the required field " &
Me.ActiveControl.Name
 
Hi,

How can I add an error handler to the whole form?
I know that when I add an error handler I can put it in the
OnError line in the right event (e.g. OnCurrent),
but what is the "FORM's Error event"?

Thank you!
 
OK, I've found it (in the Form's properties).
sorry for the silly question.. :-),

and thank you very much for your help!!

Amir said:
Hi,

How can I add an error handler to the whole form?
I know that when I add an error handler I can put it in the
OnError line in the right event (e.g. OnCurrent),
but what is the "FORM's Error event"?

Thank you!


field
 
Back
Top