Results 1 to 8 of 8

Thread: DateTime Picker - Can't figure this out. [RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Resolved DateTime Picker - Can't figure this out. [RESOLVED]

    I have a DateTime picker on my form that allows the user to select an "End Date" for how long a record should be written to the database. After having a tester run my program yesterday I was told I should not allow the user to enter an "End Date" that was earlier than the "Start Date". Makes sense.

    So this morning I have coded the following.
    The MsgBox displays when it should, and the date on the dtPicker changes to today's date, BUT the calander of the dtPicker is still open displaying the original date the user picked. How do I close the calendar part?
    I thought the "REFRESH" statement would do it...but nope.
    Or is there a better way to do this alltogether??


    VB Code:
    1. Private Sub dtEndDate_Change()
    2. If dtEndDate.Value < MonthViewClinic.Value Then
    3.    MsgBox "You cannot select an end date that occurs before the start date", vbInformation, "Invalid Selection"
    4.    dtEndDate.Value = MonthViewClinic.Value
    5.    
    6.    dtEndDate.Year = Year(Now)
    7.    dtEndDate.Month = Month(Now)
    8.    dtEndDate.Day = Day(Now)
    9.    dtEndDate.Refresh
    10.    Exit Sub
    11. End If
    12. End Sub
    Last edited by The_Grudge; Jun 3rd, 2005 at 12:20 PM.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: DateTime Picker - Can't figure this out.

    I don't know how to solve the calendar problem besides there are other problems you will encounter with your code.

    For example, if MonthViewClinic.Value is Jun 1, 2005 and you click on May 31 you will get the error.

    Invalid Property Value on the line
    dtEndDate.Month = Month(Now)

    I would just set DatePicker.MinDate property to the MonthViewClinic.Value instead. The user will never be able to select a date beyond the MinDate and will not be interrupted by annoying message boxes.

  3. #3
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: DateTime Picker - Can't figure this out.

    I have a form like yours here's what i did. And it seems to work.

    VB Code:
    1. Private Sub dtpfrmDateEnd_Change()
    2.     If dtpfrmDateEnd.Value < dtpfrmdatebeg.Value Then
    3.         MsgBox "You cannot select an end date that occurs before the start date", vbInformation
    4.         dtpfrmDateEnd = Date
    5.         dtpfrmDateEnd.Refresh
    6.     End If
    7. End Sub

    I tried it without the refresh and it seemed to work that way too.

    HTH
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: DateTime Picker - Can't figure this out.

    I don't know exactly how your Form is designed but I personally never like programs that doesn't allow me to select whatever values I want, in whatever order I like. Meaning that you're actually forcing the user to select the start date before the end date. But what if after I've selected a valid end date I go back and change the start date to something later then the end date? Would that be acceptable? Of course it shouldn't but if you also restrict the user so they can't select a start date after the current value of the end date the user must learn that in some cases you must select an end date before the start date and in some cases you must do it the otherway around.

    So what do you think, is that a good design? Wouldn't it be better to allow the user to select whatever he/she wants and do the validation before the Form is closed (or whatever you do before the settings kick in to action). Just a friendly suggestion.

  5. #5
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: DateTime Picker - Can't figure this out.

    That's a good suggestion, Joacim. I went back and changed that so that it occurs when the user clicks the "OK" button.

    VB Code:
    1. Private Sub cmdOK_Click()
    2. If dtpfrmDateEnd.Value < dtpfrmdatebeg.Value Then
    3.     MsgBox "You cannot select an end date that occurs before the start date", vbInformation
    4.     dtpfrmDateEnd = Date
    5.     dtpfrmDateEnd.Refresh
    6.     Exit Sub
    7. End If
    8. setDate
    9. bDateFlag = True
    10. Unload Me
    11. End Sub

    Do you think this is a better design?

    Thanks
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: DateTime Picker - Can't figure this out.

    Much better, there are times where instant validation might be the best approach but in this case it's better to let the user fill in the values and check them before they are stored.

  7. #7

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Re: DateTime Picker - Can't figure this out.

    Yeah, good call. I was working under the assumption that the user would do everything in Logical order. We all know that rarely happens!

  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: DateTime Picker - Can't figure this out.

    Well, most users would probably fill in the Form in logical order. But if you use your first approach I shouldn't be able to start by picking a start date that is later then the current setting of the End date, which in that case means that I need to set the end date first and then go back to set the start date. That's not logical is it?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width