calculating age from DOB field

access_learner

Registered User.
Local time
Today, 10:25
Joined
Oct 5, 2004
Messages
13
hello all.

Im still kinda learning access.

i want to have a field Age which is displayed on my form and i want it to be calculated from the DOB entered.
I dont want users to edit this field either.
I know i should have another field where the user enters in Age manually because of data redundancy and it can be calculated without having to store it, and because the age will be changing each year when the person is getting older.

so how can i place some sort of formula or something into this Age field on my form to calculate how old someone is from the DOB which was entered?

thanks. access_learner
 
One possible way is to set the age field''s control source to the following:

=Left((Now()-[DOB FIELD])/365,InStr((Now()-[DOB FIELD])/365,'.')-1)

substitute the name of your dob field for [DOB FIELD]

This function subtracts DOB from the current date, divides that result by 365 to get years, and then only displays the digits to the left of the decimal point.

Hope this helps.

-Chappy
 
thanks for the link.

i also had a quick search on google and found how to do it.

My other question is how can i generate statistics from this calculated data ???

because i want to see the range of ages of students in the database.
But because the field is generated each time when the dob is shown, it doesnt work on my statistics page.

will i have to store the age field ??? and if so will the age field update it self when someones age changes?

any ideas??

thanks, access_learner
 
Last edited:
If you store anything it does automaticaly change... thats why just about RULE #1 you learn as a developer is to NOT store calculated values.

If you use your function in a query you can do all the statistics you may need.

Regards
 
ok well i dont exactly know how to write a function like this is VB.

i am currently generating stats from stored data. But i dont know how to generate stats from calculated data based on stored data.

I tried, but it does not work correctly.
i tried to upload my db but its too big to be uploaded...just, and i cant compress it anymore in winzip.

on my stats form i want to generate and show the Age range of students which is calculated from their DOB.
i have generated the Age field in my form, but dont know how to generate stats from a bunch calculated fields.


can someone help me ? my access knowledge is not advanced enough for the things im trying to do :(
 

Users who are viewing this thread

Back
Top Bottom