age and agecat

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
 
F

Fredg

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top