Create a table, with a record for each age group.
The table will have 2 fields, like this:
- MinAge Number primary key
- AgeName Text
Sample data:
MinAge AgeName
====== ========
0 Under 10
10 10 - 15
16 16 - 21
22 22 - 30
31 Over 30
Now that you have taught Access about your age groups, you can match the
age group to the person's age. One approach would be to copy the ELookup()
function from this age into a standard module in your database, and then use
an expression like this (as one line):
=ELookup("AgeName", "AgeGroupTable",
"MinAge <= " & Nz([Age],0), "MinAge DESC")
Another approach would be to use a subquery, by typing something like this
into the Field row in query design:
AgeGroup: (SELECT TOP 1 AgeName
FROM AgeGroupTable
WHERE MinAge <= Nz([Age],0)
ORDER BY MinAge DESC)
If subqueries are new, here's an introduction:
http://allenbrowne.com/subquery-01.html
Finally, if you have lots of records and find these approaches are too slow,
here's a more detailed solution from Tom Ellison:
Lookup in a range of values in a query
at:
http://allenbrowne.com/ser-58.html
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Reply to group, rather than allenbrowne at mvps dot org.
Kebs said:
I am beginner in access. I am working on a table with DOB to calculate the
age. This is fine but my problem is to place the calculated Age field into
AgeGroups eg 10-16, 16-21, 22-30 etc. Is there any way to create a query
that would place the records in the appropriate group? Please help.