Question about Date field error

  • Thread starter Thread starter Joe Cilinceon
  • Start date Start date
J

Joe Cilinceon

I was wondering if there is a way to stop the error message that appears
when you enter a date that is out of range in a text box for dates. For
example if you entered 2/29/05 it would cause an error as there is only 28
days in this month. I would like to trap this error and put in the proper
last day of the month by code. Any suggestions would be appreaciated.
 
I was wondering if there is a way to stop the error message that appears
when you enter a date that is out of range in a text box for dates. For
example if you entered 2/29/05 it would cause an error as there is only 28
days in this month. I would like to trap this error and put in the proper
last day of the month by code. Any suggestions would be appreaciated.

You would trap that error in the Form's Error event.

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.
 
Back
Top