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
Printable View
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
Can you post your code ?
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.
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
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.
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