Calculating age

  • Thread starter Thread starter Greg Smith
  • Start date Start date
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.
 
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
 
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.
 
Back
Top