Field: Age: AgeYears([Date of Birth])
When you create a calculated field the name of the field is preceded by a colon. You have 2 colons, thus 2 names, thus error.
Remove one of the names from that query:
CurrentAge: AgeYears([Date of Birth])
Field: Age: AgeYears([Date of Birth])
I am sorry doc but this is fundamentally flawed, a person born 1/1/15 will be 1 year old on 1/1/16 but that is only 365 days thus your calculation will return 0, thus it is incorrect on all birthdays for three out of four years , below is the correct calculationNow, as to the module, which is certainly correct: There is another way to do this that might be easier to write in a query without needing a module:
Code:Int( ( CDbl(Now()) - Cdbl(Birthday)) / 365.25 )
I think the ONLY time this will be wrong (and it will be wrong only one day per leap year) would be on Feb 29th of a leap year for someone whose birthday was Mar 1st of a non-leap year. Note also that if you happen to be computing the age of Methuselah, the correct fraction is 356.2422.
This works because dates are internally expressed in the system as DOUBLE-format real numbers that are the difference in days and fractions thereof since the system reference date. The above formula computes the difference between now and the birthday as a number of days and fractions, then divides that by the number of days in a year, then truncates it. (Do NOT use a rounding function for this purpose!)
For someone older than, say, 15 years old, the odds are pretty good for this to be right 99.93% of the time. The older the person is, the better the odds get.
I am sorry doc but this is fundamentally flawed, a person born 1/1/15 will be 1 year old on 1/1/16 but that is only 365 days thus your calculation will return 0,
Int( ( 1 + ( CDbl(Now()) - Cdbl(Birthday) ) ) / 365.25 )
As to the other point...
I'm old, soStill missing my main point, see post #23: http://www.access-programmers.co.uk/forums/showpost.php?p=1465034&postcount=23
What happens if you're 21 again ?
Int( ( 1 + ( CDbl( Now() ) - Cdbl( Birthday ) ) ) / 365.25 )