Is there a way to get the age of a client to appear next to the
birthdate?
I have a form, that people will fill in - once they filled in the
birthdate, is it possible to have a box next to it that will display
their age?
Im assuming that i'll need a code or something, where does that
usually go?
thanks for any help.
Mr B - 12 Sep 2007 03:50 GMT
Place the following code in a standard Module:
Function dhAge(dtmBD As Date, Optional dtmDate As Date = 0) As Integer
'Calculate a person's age, given the person's birth date and an
'optional "current" date
If dtmDate = 0 Then
'Did the caller pass in a date? If not, use the current date.
dtmDate = Date
End If
dhAge = DateDiff("yyyy", dtmBD, dtmDate) + (dtmDate <
DateSerial(Year(dtmDate), _
Month(dtmBD), Day(dtmBD)))
End Function
Be aware of wraping in the code as posted.
Then add the following line to the "Control Source" of the text box where
you want the Age to appear:
=IIf(IsNull([DOB]),"",dhAge([DOB]))
The "DOB" is the field that has the birthday.

Signature
HTH
Mr B
askdoctoraccess dot com
> Is there a way to get the age of a client to appear next to the
> birthdate?
[quoted text clipped - 7 lines]
>
> thanks for any help.
Maelinar - 12 Sep 2007 04:50 GMT
Read my post 2 items down...
> Is there a way to get the age of a client to appear next to the
> birthdate?
[quoted text clipped - 7 lines]
>
> thanks for any help.
fredg - 12 Sep 2007 04:53 GMT
> Is there a way to get the age of a client to appear next to the
> birthdate?
[quoted text clipped - 7 lines]
>
> thanks for any help.
As the control source of an unbound control:
=DateDiff("yyyy",[DOB],Date())-IIf(Format([DOB],"mmdd")>Format(Date(),
"mmdd"),1,0)
Where [DOB] is the name of the field that stores the Date of Birth.
You do know, I hope, that this Age computation should NOT be stored in
any table.
Just compute it and display it on a form or report, as needed.

Signature
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
sea_minerals@yahoo.com - 12 Sep 2007 05:22 GMT
Thank you.
It kinda of worked! On the form, once the birthdate is filled in the
age automatically appears - which is great!
When i view a report or the table, in the 'age' column it just has a
'0' is this right, or can it also display the age?
thanks again
> > Is there a way to get the age of a client to appear next to the
> > birthdate?
[quoted text clipped - 22 lines]
> Please respond only to this newsgroup.
> I do not reply to personal e-mail
Maelinar - 12 Sep 2007 06:52 GMT
Laymans Explanation:
As fredg and John have already said, we shouldn't be storing data that
changes in the database. For example - do you want to have to go through your
database every day to update individual ages when you can just calculate them
as needed ?
I've posted a detailed solution that I'm sure you will be able to use for
your problem 2 below...
Mæl.
> Thank you.
>
[quoted text clipped - 32 lines]
> > Please respond only to this newsgroup.
> > I do not reply to personal e-mail
fredg - 12 Sep 2007 15:39 GMT
> Thank you.
>
[quoted text clipped - 32 lines]
>> Please respond only to this newsgroup.
>> I do not reply to personal e-mail
On the report, simply repeat the calculation that you used on the
form.
There should NOT be an Age field in your table.
A stored Age is sure to be incorrect within, at most, 365 days.

Signature
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail