Calculating age

G

Greg Smith

I have a form with information about patients.

I have a textbox for date of birth.
I have a textbox for date of admission.

I would like to fill an other textbox with the person's age at the time of
admission.

Any help is greatly appreciated.
 
F

fredg

Greg Smith said:
I have a form with information about patients.

I have a textbox for date of birth.
I have a textbox for date of admission.

I would like to fill an other textbox with the person's age at the time of
admission.

Any help is greatly appreciated.

In a query:
Age: DateDiff("yyyy", [DOB],[DateOfAdmisson]) - IIF(Format([DOB], "mmdd") >
Format([DateOfAdmisson], "mmdd"), 1, 0)

Directly as the control source of an unbound control on your form or in a
report:
=DateDiff("yyyy",[DOB],[DateOfAdmisson])-IIf(Format([DOB],"mmdd")>Format([Da
teOfAdmisson],
"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.

Fred
 
G

Guest

Create a tetxbox in your form and type the following in its Control Source:
=IIf([DOB]="","",DateDiff("yyyy",[DOB],Date())+(Format([DOB],"mmdd")>Format(Date(),"mmdd")))

DOB is the name of the fields that has the date of birth, this coding
formats to number of years. For example: 26

Make sure to protect this textbox so age cannot be modified.
 

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