Calucate Age

J

jeremy0028

I have a date of birth field along with a text box called age

What I want to do is if a user enters date of birth it will show the
age in the text box called age.
Any ideas
 
F

fredg

I have a date of birth field along with a text box called age

What I want to do is if a user enters date of birth it will show the
age in the text box called age.
Any ideas


Directly as the control source of an unbound control:
=DateDiff("yyyy",[DOB],Date())-IIf(Format([DOB],"mmdd")>Format(Date(),
"mmdd"),1,0)

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.
 
G

Gina Whipp

I use...

In a Event Procedure...

If Date < [apDateOfBirth] Then
Me.txtAge = Format(Date, "yyyy") - Format([apDateOfBirth], "yyyy")
Else
Me.txtAge = (Format(Date, "yyyy") - Format([apDateOfBirth],
"yyyy")) - 1
End If

OR

On the form or report in a text box...

=IIf(Date()<[YourDateOfBirthField],Format(Date(),"yyyy")-Format([YourDateOfBirthField],"yyyy"),(Format(Date(),"yyyy")-Format([YourDateOfBirthField],"yyyy"))-1)

This way if the birthday is after todays date I'm still getting the correct
age.

HTH,
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II
 

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