Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trapping Date Errors

Status
Not open for further replies.

LarryDeLaruelle

Technical User
May 19, 2000
1,055
US
What is the best way to trap for date errors without getting the generic Access Error message?

Right now I am using an unbound text box to accept data entry and using this code in the Before Update event:

Private Sub txtCompDate_BeforeUpdate(Cancel As Integer)

If Not IsDate(txtCompDate) Then
MsgBox "This is not a valid date. Please Reenter", vbOKOnly
Cancel = -1
Else
ProjComp = txtCompDate
End If

End Sub

This works after a fashion but it is still not very user friendly.

Although I have set the Input Mask to Short Date, it does not give me the standard formatting for the user to do data entry (if I bind it to a control I get the generic error).

Nor can I set the value to an empty string or to null to give the user an empty field in which to reenter the date.

How have the gurus handled this situation?

Thanks.

Larry De Laruelle
ldelaruelle@familychildrenscenter.org

 
One of the easiest ways is to bind it to a date field. If your form is bound to a table, just add a new column with data type date. You need no further input mask or anything. Access automatically converts 1-1-02 or 1/1/02 to 01/01/2002
 
tman138:

Tried that. In fact that was how I started. If the control is bound then I get the generic error message which means diddly squat to users.

What I am trying to trap for are those dates which are not legitimate such as 04/31 or 02/29/02.

I've been tinkering and moved the code to the After Update event which seems to work better. I still don't get the formatting when I first tab into the field and modify it although the formatting is there when I reset the focus after the custom message.

Why oh why could't Microsoft provide a trappable error for invalid dates. Sometimes this stuff drives me crazy (which is a very short trip).
Larry De Laruelle
ldelaruelle@familychildrenscenter.org

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top