L
Linda in Iowa
I recently posted this and received a reply as follows. Can anyone tell me
how to make it work as I have not been able to get correct results if any.
I am using Access 2003.
Here is my original post:
----------------------------
I have an age field that is calculated from a birthdate.
I want to count the number of records in age groups such as 10-19, 20-29,
30-39, 40-49.
the Birthdate field has date entered as mm/dd/yyyy
The Age field is calculated by using ((Now()-[MbrBirthdate])/365)
When I specify an age group in the criteria area of the calculated age field
and Count on the Birthdate field it will show each age and count it as 1. I
want the total number of records in that group.
Here is the SQL of the query I currently have:
SELECT DISTINCTROW ((Now()-[MbrBirthdate])/365) AS [Main member age],
Count(MBRS.MbrBirthdate) AS CountOfMbrBirthdate
FROM MBRS
GROUP BY ((Now()-[MbrBirthdate])/365), MBRS.Memtype, MBRS.ExpDate
HAVING (((((Now()-[MbrBirthdate])/365))>69.9 And
(((Now()-[MbrBirthdate])/365))<80) AND ((MBRS.Memtype)<>"comp") AND
((MBRS.ExpDate)>Date()))
ORDER BY ((Now()-[MbrBirthdate])/365) DESC;
Also is it possible to show the counts for all age groups in one query?
Here is the response I am trying to get to work.
---------------------------------------------------
For the most flexibility, I'd suggest an AgeGroups table with two fields:
Age
(Long Integer) and Agegroup (text), with values like
0 "Child"
10 "10-19"
20 "20-29"
and so on.
Since a year isn't exactly 365 days (leap years!), dividing by 365 won't
give
an exact age as of the previous birthday. Instead use an expression:
DateDiff("yyyy", [MbrBirthdate], Date()) - IIF(Format([MbrBirthdate],
"mmdd")
Include the AgeGroups table in the query with this expression as a criterion
Sort ascending by Age and set the Top Values property of the query to 1 to
select the age group.
--
how to make it work as I have not been able to get correct results if any.
I am using Access 2003.
Here is my original post:
----------------------------
I have an age field that is calculated from a birthdate.
I want to count the number of records in age groups such as 10-19, 20-29,
30-39, 40-49.
the Birthdate field has date entered as mm/dd/yyyy
The Age field is calculated by using ((Now()-[MbrBirthdate])/365)
When I specify an age group in the criteria area of the calculated age field
and Count on the Birthdate field it will show each age and count it as 1. I
want the total number of records in that group.
Here is the SQL of the query I currently have:
SELECT DISTINCTROW ((Now()-[MbrBirthdate])/365) AS [Main member age],
Count(MBRS.MbrBirthdate) AS CountOfMbrBirthdate
FROM MBRS
GROUP BY ((Now()-[MbrBirthdate])/365), MBRS.Memtype, MBRS.ExpDate
HAVING (((((Now()-[MbrBirthdate])/365))>69.9 And
(((Now()-[MbrBirthdate])/365))<80) AND ((MBRS.Memtype)<>"comp") AND
((MBRS.ExpDate)>Date()))
ORDER BY ((Now()-[MbrBirthdate])/365) DESC;
Also is it possible to show the counts for all age groups in one query?
Here is the response I am trying to get to work.
---------------------------------------------------
For the most flexibility, I'd suggest an AgeGroups table with two fields:
Age
(Long Integer) and Agegroup (text), with values like
0 "Child"
10 "10-19"
20 "20-29"
and so on.
Since a year isn't exactly 365 days (leap years!), dividing by 365 won't
give
an exact age as of the previous birthday. Instead use an expression:
DateDiff("yyyy", [MbrBirthdate], Date()) - IIF(Format([MbrBirthdate],
"mmdd")
Format(Date(), "mmdd"), 1, 0)
Include the AgeGroups table in the query with this expression as a criterion
= DateDiff("yyyy", [MbrBirthdate], Date()) - IIF(Format([MbrBirthdate],
"mmdd") > Format(Date(), "mmdd"), 1, 0)
Sort ascending by Age and set the Top Values property of the query to 1 to
select the age group.
--