Ages

ddrew

seasoned user
Local time
Today, 14:31
Joined
Jan 26, 2003
Messages
911
I have a form with a Date of Birth Field on iy, along with a couple of check boxes. I want to be able to code the Date of Birth Box to say:

If the elapsed time from the date that was input to todays date is greater than 16 years then Check box 1 = true

If the elapsed time from the date that was input to todays date is less than 16 years then Check box 2 = true.

I dont think its difficult and I think I know where Im going with it just notsure where to start!
 
Use the following code on the After_Update event of the textbox

Code:
If Me.NameOfTextBox > DateAdd("yyyy", -16, Date) Then
Me.NameofCheckbox1= True
Else
Me.NameofCheckbox2 = True
End If

HTH
 
Sounds like you have a repeating group at the table level.
 
DateAdd("yyyy", -16, Date)
does not equate to age since it only looks at the difference in years, without consideration for months and days. Need to take it a step further with something like:

DateDiff("yyyy", dDOB, date()) + _
(date() < DateSerial(Year(date()), Month(dDOB), day(dDOB)))

HTH - Bob
 
I think things are starting to get confusing. I have a database that covers a karate club. Within the club are Juniors and Seniors. Anyone under the age of 16 is a senior. So, at present I input the birthday and then MANUALLY work out if the person is 16. I want to automate the process on two fronts. Firstly when I input the persons date of birth when they first join the club, it automatically selects Junior or Senior as appropriate. Secondly, for people who have been in the club for a while, the database automatically changes to SENIOR when a person reacghes the age of 16. I have attached a sample database to show what I mean, (no code though as that is what I am asking to be shown!)
 
Bob - DateAdd does indeed only check the difference in days, months or years depending upon what is specified, but if someone enters a date, which is more than 16 years from the date it was entered, they are older than 16.

DDrew - I've attached the database, it should do want you wanted.

Here's what it does:

1. When the form is opened it runs 2 update queries, which check the date of birth against today's date and changes the membership status from Junior to Senior if the person is older than 16. You can test this by changing the date of birth in the table and then opening the form.

2. I've placed the code I suggested earlier in the thread, so that after a person enters the date of birth, either the Junior or Senior box is checked depending on whether the person is over 16 or not. I have also set the checkboxes properties to 'Enabled = No, Locked = Yes'. This stops anyone from being able to check the boxes, they must rely on the code to decide, which box should be checked.

HTH
 

Attachments

Dave -

You're absolutely correct! I was erroneously looking at it as a DateDiff() vs
DateAdd() issue. Sorry about that.

Bob
 

Users who are viewing this thread

Back
Top Bottom