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!

Dates and text fields

Status
Not open for further replies.

halx

Programmer
Jun 5, 2002
35
FR
Hello,

I have two text fields in a form: txtDate1 and txtDate2, and they are supposed to contain dates (I have put a mask like **/**/**** for dates).
But I cannot compare txtDate1 and txtDate2 correctly.
The expresion (me.txtDate1 > me.txtDate2) still compares 2 strings an not 2 dates.
What can I do ?

Thanks

Alex
 
Use CDate - little example:

Sub TestDate()
MyString = "01/06/1999"
MyOtherString = "31/08/1999"

MyDate = CDate(MyString)
MyOtherDate = CDate(MyOtherString)

MsgBox ("There are " & (MyOtherDate - MyDate) & " days between " & vbNewLine & _
FormatDateTime(MyDate, 1) & vbNewLine & _
"and" & vbNewLine & _
FormatDateTime(MyOtherDate, 1))

End Sub

Hope I understood your problem right!
 
Yes, this is the solution.
Thanks a lot !

Alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top