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!

Excel form does not recognize date entered

Status
Not open for further replies.

Eprice

Technical User
May 6, 2003
209
US
Hi,
This is Excel 2000. I have a form where the user enters a next visit date. I am trying to stop the user from entering a date that has already passed. I have this as an error checker but it does not work, just lets the form unload and enters the past date.
stDate1 refers to the value entered in a text box on my form.
Dim stdt
stdt = FormatDateTime(stDate1, vbShortDate)
If stdt <= Now() Then
MsgBox "You cannot enter a date that has already passed. Please correct the Next Visit date."
Exit Sub
End If

Does anyone know why this is not working. Thanks,
Lisa
 
Works for me:

Code:
Dim stdt As Date

If IsDate(stDate1.Text) Then
    stdt = FormatDateTime(stDate1, vbShortDate)
Else
    MsgBox "Not a valid Date."
    Exit Sub
End If

If stdt <= Date Then
    MsgBox "You cannot enter a date that has already passed. Please correct the Next Visit date."
Exit Sub

End If

Have fun.

---- Andy
 
You have a date entered in a text box, that is stored as string. FormatDateTime converts date to string, you rather need the opposite. Convert string to date instead, use CDate function.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top