Results 1 to 7 of 7

Thread: [RESOLVED?] DTPicker & Validation

Threaded View

  1. #1

    Thread Starter
    Addicted Member yolandre's Avatar
    Join Date
    Oct 2004
    Posts
    177

    Resolved [RESOLVED?] DTPicker & Validation

    Hi all!

    I am just about to give up hope... I use DTPicker to enable the user to select a valid date within a certain period. The valid period is specified using MaxDate and MinDate and when using the mouse to select the date works perfectly, i.e. the user cannot select any date prior to MinDate nor can the user select a date later than the MaxDate. However...

    If the user uses the keyboard and change for example the century and year portion (yyyy) of the date picker to a year prior to the MinDate or later than the MaxDate the DTPicker accepts the ammended date...

    The validation of the date resides in the KeyDown event of the DTPicker, i.e. the user needs to press ENTER before continuing to the next data field.

    Please consider the following sample:

    Private Sub dpStartDate_KeyDown(KeyCode As Integer, Shift As Integer)

    If KeyCode = vbKeyReturn Then
    If dpStartDate.Value > dpStartDate.MaxDate Then
    MsgBox "Invalid Input - The date is later than the maximum date!"
    dpStartDate.Value = dpStartDate.MaxDate
    dpStartDate.SetFocus
    ElseIf dpStartDate.Value < dpStartDate.MinDate Then
    MsgBox "Invalid Input - The date is earlier than the minimum date!"
    dpStartDate.Value = dpStartDate.MaxDate
    dpStartDate.SetFocus
    ElseIf dpStartDate.Value <= dpStartDate.MaxDate And dpStartDate.Value >= dpStartDate.MinDate Then
    dpEndDate.MinDate = dpStartDate.Value
    dpEndDate.Enabled = True
    dpEndDate.SetFocus
    End If
    End If

    End Sub

    Even with the above code the user still gets away... Then, as a final attempt, I included code in the Validate event of the DTPicker as follow:

    Private Sub dpStartDate_Validate(Cancel As Boolean)

    If dpStartDate.Value > dpStartDate.MaxDate Then
    Cancel = True
    dpStartDate.SetFocus
    ElseIf dpStartDate.Value < dpStartDate.MinDate Then
    Cancel = True
    dpStartDate.SetFocus
    End If

    End Sub

    The effect? The DTPicker accepts the month and date specified and then assumes the MaxDate's year and century and immediately passes focus to the next data field. Out of frustration I added a simple check ("MsgBox dpStartDate.Value" ) and without exception each time I clicked on the message box's OK button the validation worksperfectly. It almost appears as if the validations process needs to be slowed down...

    Any suggestions?
    Last edited by yolandre; Feb 1st, 2008 at 02:59 AM.

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