|
-
Jan 31st, 2008, 08:27 AM
#1
Thread Starter
Addicted Member
[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.
-
Jan 31st, 2008, 08:33 AM
#2
Re: DTPicker & Validation
<rant>My first suggestion would be to tell the users not to do that, or their own data could become worthless.
There are responsibilities which should be born by them.</rant>
Have said that, I normally pop the selected date from a data picker into a textbox (which is Locked) and do my validations on what is in the textbox.
-
Jan 31st, 2008, 08:48 AM
#3
Thread Starter
Addicted Member
Re: DTPicker & Validation
LOLZ! Thanks Hack! Unfortunately the app is to be deployed in a country where computer literacy is virtually non-existent amongst the end users of the app and data quality still is most valuable! For this reason I doubt whether warning them not to do that stupendous act will have any positive effect...
I have given the idea of using a text box some thought, but man, all that effort of alpha testing right from the beginning….
I suppose if all else fails it will be the only solution.
Thanks for the speedy reply – much appreciated!
-
Jan 31st, 2008, 08:52 AM
#4
Re: DTPicker & Validation
 Originally Posted by yolandre
I have given the idea of using a text box some thought, but man, all that effort of alpha testing right from the beginning….
There in lies the age old problem for all programmers yolandre!
The less literate the audience, the more work for the programmer....the more work, the more testing....the more testing....the more work.
And, after after all of that, someone will stumble across a way to break it. 
(Sometimes I think I should have following my grandfather's advice - he wanted me to be a plumber. )
Last edited by Hack; Jan 31st, 2008 at 09:17 AM.
-
Jan 31st, 2008, 08:55 AM
#5
New Member
Re: DTPicker & Validation
Better try this
vb Code:
Private Sub DTPicker1_Change()
If DTPicker1.Value > DTPicker1.MaxDate Then
MsgBox "Please select the valid date"
DTPicker1.Value = Date
End If
End Sub
-
Jan 31st, 2008, 09:01 AM
#6
Thread Starter
Addicted Member
Re: DTPicker & Validation
LOLZ! At least I had the pleasure of a good couple of laughs because of all of this! Yep Hack, been there myself... Why didn't I become a mechanic? Yep, this line of works demands a special kind of human!
shasunder: Many thanks for the valid attempt! Been there, done that & using the t-shirt to clean my LCD... Doesn't help a bit.
-
Feb 1st, 2008, 02:58 AM
#7
Thread Starter
Addicted Member
Re: DTPicker & Validation
Many thanks to all who assisted! There is no 100% working solution, thus decided to completely eliminate keyboard input.
Regards @
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|