LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Userforms and Dates

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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Userforms and Dates Barb Reinhardt Excel Programming 3 November 3rd 06 03:45 PM
I need some help with userforms T.c.Goosen1977[_9_] Excel Programming 0 June 30th 06 09:24 AM
userforms BeckyH Excel Programming 2 January 31st 06 12:20 PM
dates in userforms Ben G Excel Programming 0 July 8th 03 04:55 PM
dates in userforms Ben Guenther Excel Programming 0 July 8th 03 03:44 PM


All times are GMT +1. The time now is 02:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"