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 Chris Miller 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 1

Status
Not open for further replies.

LarryDeLaruelle

Technical User
May 19, 2000
1,055
US
I have tried using the statement:

If Not IsDate(DateField) then
Pop up a message to the user
End If

I have tried this in the After Update, On Exit, Lost Focus events but still get the Access Error message instead of my custom if an invalid date is entered.

Is this the right approach and, if so, where should this code be placed?

If this isn't the way to go, how do I trap for invalid dates?

Thanks much. Larry De Laruelle
ldelaruelle@familychildrenscenter.org

 
Larry, take a look at : Thread702-209965

Different problem but quite similar really.

Regards
Rod
 
Rod:

Thanks. That is what I needed.

The curious thing is that there does not seem to be an error code for the invalid date issue. When I trapped for it and displayed the error, I got a zero and no description.

Here's the code I set up and it seems to do the trick quite nicely.

Private Sub Form_Error(DataErr As Integer, Response As Integer)

If Not IsDate(Date) Then
MsgBox "This is not a valid date" & vbCrLf & vbCrLf & "Please Reenter"
Response = acDataErrContinue
Else
MsgBox "Error: " & Err & "--" & Err.Description & vbCrLf & vbCrLf _
& "Contact the Administrator"
End If

End Sub

Thanks again. Larry De Laruelle
ldelaruelle@familychildrenscenter.org

 
Larry,

Something is wrong with your error trap. A zero is no error. If you are receiving an error for an invalid date it will not be a zero. If your breakpoint if after an "On Error Resume Next" or "On Error GoTo ..." That would reset the error code to zero.

Growth follows a healthy professional curiosity
 
scking:

You are probably right. I was just relaying what I saw happening as I stepped through the code.

What happened if I entered an invalid date (i.e., 02/29/2002) was that I received a generic error message.

When I trapped for the error in the Form_Error event and displayed the resulting Err Number it showed a zero with a blank description.

I looked all through the list of numbered errors and did not find one specific to a date error. This seems to be working -- at least I haven't heard any screams from the users - - - yet. Larry De Laruelle
ldelaruelle@familychildrenscenter.org

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top