age and agecat

  • Thread starter Thread starter leaf
  • Start date Start date
L

leaf

Hello,

I would like to have age and agecat be automatically
filled in when Date of Birth is filled in on an ACCESS
form. Agecat is a categorical variables, ie, 3 categories
referring to ages <40, beteen 40 and 50 and >50. This can
be easily accomplished in SAS, but we want this done on an
ACCESS form so that data entry people will know
immediately the age of the person and will know what
subsequent questions to ask.

I am new to ACCESS. Please let me know the detailed steps
to create age and agecat. My intuitive thought will be in
the table design view, somehow define the variable as the
calculated age from date of birth.

Thank you very much in advance.

leaf
 
leaf said:
Hello,

I would like to have age and agecat be automatically
filled in when Date of Birth is filled in on an ACCESS
form. Agecat is a categorical variables, ie, 3 categories
referring to ages <40, beteen 40 and 50 and >50. This can
be easily accomplished in SAS, but we want this done on an
ACCESS form so that data entry people will know
immediately the age of the person and will know what
subsequent questions to ask.

I am new to ACCESS. Please let me know the detailed steps
to create age and agecat. My intuitive thought will be in
the table design view, somehow define the variable as the
calculated age from date of birth.

Thank you very much in advance.

leaf
Leaf,
While there is no difficulty in showing Age and AgeCat on your form,
neither should be saved to any table. It's not necessary.
Here is how to compute Age and AgeCat in contros on a form.

Code the DateOfBirth control's After Update event:
** Watch for word wrap. there is only 1 > used in the expression.**

[AgeConteol] = DateDiff("yyyy", [ADate], Date) - IIf(Format([ADate],
"mmdd") > Format(Date, "mmdd"), 1, 0)

[AgeCatControl] = GroupAge(AgeControl)

Next, add a new function on the Form's code sheet:
Public Function GroupAge(AgeIn)
Select Case AgeIn
Case Is < 40
GroupAge = 1
Case 40 to 50
GroupAge = 2
Case Is >50
GroupAge = 3
End Select

End Function

When the Date of Birth is entered, the other 2 controls will be filled
with the Age and AgeCat.
 
Back
Top