View Full Version : Solved: Compare dates on userform
clhare
09-07-2007, 03:24 AM
I have a user form with two sets of Start and End dates. I need to do two things with each set of these dates:
1) make sure that value entered is in fact a date
2) make sure the End date entered does not precede the Start date entered?
How can I accomplish this?
Nelviticus
09-10-2007, 07:27 AM
You can use IsDate() to test whether an expression (i.e. the contents of a text box) is convertable to a date and then you can use CDate() to convert it. Something like this:
Sub Dates()
Dim sDate1 As String
Dim sDate2 As String
Dim dDate1 As Date
Dim dDate2 As Date
sDate1 = "15/10/1995"
sDate2 = "10/09/2007"
If IsDate(sDate1) Then
dDate1 = CDate(sDate1)
If IsDate(sDate2) Then
dDate2 = CDate(sDate2)
If dDate1 > dDate2 Then
MsgBox sDate1 & " is later than " & sDate2
ElseIf dDate2 > dDate1 Then
MsgBox sDate2 & " is later than " & sDate1
Else
MsgBox "Both dates are the same"
End If
End If
End If
End Sub
Regards
clhare
09-10-2007, 08:13 AM
Perfect! It works great! Thank you so much!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.