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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for a valid date

Status
Not open for further replies.

dlpastel

Programmer
Aug 8, 2002
114
US
Is there a function or a good way to check for a valid date when a user enters a date in a text box?
ie: if a user entered 02/31/02 is there a function that knows that Feb 31st does not exist?
Otherwise, how do people typically do this.

Thanks
Dan
 
This should do the trick,

The function return False and True

MsgBox IsDate(Text1.Text)
 
IsDate can help you out there

You can do something like the following:

If ValidateDate(txtDate.Text) = False Then
MsgBox "Date is Invalid - please re-enter",vbOKOnly, "Invalid Date"
End If

Public Function ValidateDate(strDate as string) as Boolean
If IsDate(strdate) Then
ValidateDate = True
Else
ValidateDate = False
End If
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top