How do I calculate age as a default value in a table?

C

Crazy Phrog

I am trying to calculate age in a Table called herd record. I have created a
field called age. I have a field called DOB (Date of Birth). In the default
value for age, I am using the formula =now()-[DOB] But it wont accept it. Is
this because I can't do it in the default Value? or because I can't do it in
a table.
 
R

RBear3

You don't store calculated values in a properly normalized table.

If you have a DOB field, that's all you need. If you store the age, what
happens at their next birthday? Your value is wrong.

Instead, store the DOB and calculate CURRENT age in your forms, reports, and
queries. The preferred method to calculate age is...

In a query, create a new column and put the following in it:

Age:
DateDiff("yyyy",[DOB],Date())+(Format([DOB],"mmdd")>Format(Date(),"mmdd"))

To do so in a report or form, create an unbound text box and put the
following in it:

=DateDiff("yyyy",[DOB],Date())+(Format([DOB],"mmdd")>Format(Date(),"mmdd"))
 
C

Crazy Phrog

thank you so much. I understand completely what you mean. I was just hoping
to do it all at the first design level. However, it has worked brilliantly
now.

Thanks again

Crazy Phrog

RBear3 said:
You don't store calculated values in a properly normalized table.

If you have a DOB field, that's all you need. If you store the age, what
happens at their next birthday? Your value is wrong.

Instead, store the DOB and calculate CURRENT age in your forms, reports, and
queries. The preferred method to calculate age is...

In a query, create a new column and put the following in it:

Age:
DateDiff("yyyy",[DOB],Date())+(Format([DOB],"mmdd")>Format(Date(),"mmdd"))

To do so in a report or form, create an unbound text box and put the
following in it:

=DateDiff("yyyy",[DOB],Date())+(Format([DOB],"mmdd")>Format(Date(),"mmdd"))



--
Hope that helps!

RBear3
..

Crazy Phrog said:
I am trying to calculate age in a Table called herd record. I have created
a
field called age. I have a field called DOB (Date of Birth). In the
default
value for age, I am using the formula =now()-[DOB] But it wont accept it.
Is
this because I can't do it in the default Value? or because I can't do it
in
a table.
 

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