Urgent!

  • Thread starter Thread starter David Smith
  • Start date Start date
D

David Smith

I am using a Text Box - Format property set to

Medium Date. Now whenever I enter invalid date and as soon as I came out

from text box, Standard Error Message of MS-Access pops up and asks for a

valid date.



I am checking all the validation but Standard Message displays before the

execution of manual error handing procedure.

Plz guide me how to solve this problem. Its really very urgent.
 
The format has nothing to do with how you enter a date. It only affects the
display. Do you have an input mask on this text box? Also check any code
behind the form to see if there is any validation being done.

If you have an input mask, I'd suggest you delete it, as it just gets in the
way when entering a date.
 
This error is coming from the table definition itself. A
field set to data type Date/Time will not accept an
invalid date. It appears that the control validates the
data in the field even before the BeforeUpdate Event is
processed.
The only 2 ways I can think of avoiding this is
1)make your field a different data type.
or
2)Use the KeyDown event to trap the "enter" key and run
your validation there
eg.
Private Sub date_KeyDown(KeyCode As Integer, Shift As
Integer)
If KeyCode = 13 Then
If IsDate(Me.date) Then
'Add further validation here eg. valid date range
Else
MsgBox "Custom validation message"
'Prevent the enter key to be accepted
KeyCode = 0
End If
End If
End Sub

With this code however, if they click outside the box
after entring the invalid date, they will get the same
default message.
 
Use the Error event of the form.
Trap DataErr 2113.
Set Response to acDataErrContinue after displaying your custom message.
 
Back
Top