Syntax for age in a form

M

Musiwa

Help please I am triying to calculate an age in a form.
Is this possible I have the date of birth already
populated for each record and I was trying to use
datediff like in a query but this does not work in a
form. I need to know the age eachtime I use that record
 
J

John Vinson

Help please I am triying to calculate an age in a form.
Is this possible I have the date of birth already
populated for each record and I was trying to use
datediff like in a query but this does not work in a
form. I need to know the age eachtime I use that record

Set the Control Source of a textbox on the form to

=DateDiff("yyyy", [DOB], Date()) - IIF(Format([DOB], "mmdd") >
Format(Date(), "mmdd"), 1, 0)

Or you can put the same expression in a vacant Field cell in the query
and reference the calculated field as the control source.
 
S

Steve Schapel

Musiwa,

DateDiff should work ok in the control source property of an unbound
textbox on your form. One way of doing it is...
=DateDiff("yyyy",[DateOfBirth],Date())+(Format([DateOfBirth],"mmdd")>Format(Date(),"mmdd"))

- Steve Schapel, Microsoft Access MVP
 

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