Date validation and error message

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I have a text box which has a 'date' control source (data type = date/time.

When an incorrect date is entered i.e 65/01/2006 is throws (quite rightly)
an error when you attempt to go to another control
..
However the standard Access error is vauge:
"The value you entered isn't valid for this field" etc...

My question is - how do I overide this standard message and provide my
users with something more meaningful like a custom msgBox that actually
explains what the error is?

Any ideas??
 
Hi all,

I have a text box which has a 'date' control source (data type = date/time.

When an incorrect date is entered i.e 65/01/2006 is throws (quite rightly)
an error when you attempt to go to another control
.
However the standard Access error is vauge:
"The value you entered isn't valid for this field" etc...

My question is - how do I overide this standard message and provide my
users with something more meaningful like a custom msgBox that actually
explains what the error is?

Any ideas??

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 a valid date." ' Display your own message
Else
MsgBox "Error#: " & DataErr
Response = acDataErrDisplay ' Display Default message
End If

where XXXX is the error number.
 
Thanks fredg

Works like acharm!

James

fredg said:
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 a valid date." ' Display your own message
Else
MsgBox "Error#: " & DataErr
Response = acDataErrDisplay ' Display Default message
End If

where XXXX is the error number.
 
Back
Top