|
-
Nov 3rd, 2003, 03:09 PM
#1
Thread Starter
Addicted Member
Date Validate
Sorry again
I am trying to stop the user putting in a age that is older than 25 and younger than 16 and am 3 combo boxes any ideas how i can validate it???
Thanks all
Sam Lad
-
Nov 3rd, 2003, 03:17 PM
#2
Retired VBF Adm1nistrator
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 3rd, 2003, 03:24 PM
#3
What is the problem? I'm not sure of what the last part of your question (about 3 comboboxes) means, but you ought to be able to check the box during the On_Change event. If the first character typed is anything other than 1 or 2, the rest doesn't matter.
I see that you would have the problem that the user could get away with only typing 1 or 2 and then going on. For this reason, it might be safer to put validation code later on, like when the user is leaving the form. You might try it in the LostFocus event, but I don't trust that one.
-
Nov 3rd, 2003, 03:40 PM
#4
Thread Starter
Addicted Member
I have no code atm
what i require is the user to tell me there date of birth
they must
select a year by using a combobox then
to select a month then a day
then i want my program to tell them there age in yrs
-
Nov 3rd, 2003, 04:27 PM
#5
Oh, I see.
If you are using combo boxes, you will need to let the user enter all three of the parts of the date before you can do any validating. Therefore, I would suggest that you move any validation to a control button.
You could do a rough check once they have entered the year to see whether or not their age could possibly fit the range you want, but if it is at the edge of the range, you would need to check the month and possibly the day to be sure.
-
Nov 3rd, 2003, 05:54 PM
#6
VB Code:
Dim strBirthDate As String
Dim intMonths As Integer
Const UPPER_AGE = 300 ' 25 years
Const LOWER_AGE = 192 ' 16 years
strBirthDate = cboYear.Text & "/" & Format$(cboMonth.Text, "00") & "/" & Format$(cboDay.Text, "00")
If Not IsDate(strBirthDate) Then
MsgBox "Invalid date"
End If
intMonths = DateDiff("m", strBirthDate, Now())
If intMonths > UPPER_AGE Or intMonths < LOWER_AGE Then
MsgBox "Birdate out of range"
End If
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
|