D
Derek Johansen
Hey again guys,
I am practicing using a userform to perform custom type filtering based on a
criteria and a date range. The code I am using is below:
Private Sub iSubmit_Click()
Dim StartDate As Date
Dim EndDate As Date
Dim SortBy As String
If IsDate(Me.iStart.Value) = False Then
MsgBox "Please enter a valid START DATE!", vbExclamation, "Error"
Me.iStart.SetFocus
Exit Sub
End If
If IsDate(Me.iEnd.Value) = False Then
MsgBox "Please enter a valid END DATE!", vbExclamation, "Error"
Me.iEnd.SetFocus
Exit Sub
End If
If Me.iSort.Value = "" Then
MsgBox "Please select a valid SORT CRITERIA!", vbExclamation, "Error"
Me.iEnd.SetFocus
Exit Sub
End If
If Me.iEnd.Value < Me.iStart.Value Then
MsgBox "Please enter an END DATE that is after the START DATE!",
vbExclamation, "Error"
Exit Sub
End If
SortBy = Me.iSort.Value
StartDate = Me.iStart.Value
EndDate = Me.iEnd.Value
MsgBox StartDate & " comes before " & EndDate
End Sub
This code works well for me, as long as the date is within the same calendar
year. If I put "2/2/2009" and "2/3/2008" it tells me that the first date
comes before the second date, when it really should have told me to pick a
new end date!
Does anyone have any idea why it's not recognizing the year in the
comparison? I am very new to VB programming and am trying to work hard to
learn, so all help (especially explanations of why) are much needed and
APPRECIATED!!
Thanks a lot,
Derek
I am practicing using a userform to perform custom type filtering based on a
criteria and a date range. The code I am using is below:
Private Sub iSubmit_Click()
Dim StartDate As Date
Dim EndDate As Date
Dim SortBy As String
If IsDate(Me.iStart.Value) = False Then
MsgBox "Please enter a valid START DATE!", vbExclamation, "Error"
Me.iStart.SetFocus
Exit Sub
End If
If IsDate(Me.iEnd.Value) = False Then
MsgBox "Please enter a valid END DATE!", vbExclamation, "Error"
Me.iEnd.SetFocus
Exit Sub
End If
If Me.iSort.Value = "" Then
MsgBox "Please select a valid SORT CRITERIA!", vbExclamation, "Error"
Me.iEnd.SetFocus
Exit Sub
End If
If Me.iEnd.Value < Me.iStart.Value Then
MsgBox "Please enter an END DATE that is after the START DATE!",
vbExclamation, "Error"
Exit Sub
End If
SortBy = Me.iSort.Value
StartDate = Me.iStart.Value
EndDate = Me.iEnd.Value
MsgBox StartDate & " comes before " & EndDate
End Sub
This code works well for me, as long as the date is within the same calendar
year. If I put "2/2/2009" and "2/3/2008" it tells me that the first date
comes before the second date, when it really should have told me to pick a
new end date!
Does anyone have any idea why it's not recognizing the year in the
comparison? I am very new to VB programming and am trying to work hard to
learn, so all help (especially explanations of why) are much needed and
APPRECIATED!!
Thanks a lot,
Derek