Question : How can I get an accurate age to display in an Access form?

I have an Access form that I enter dates of birth into.  The query uses this formula to calculate age "=Date()-[txtDOB2]";however, anyone under about 30 shows up as an age of 1927 or a similar number.  Older ages display correctly.  Does anyone know how to fix this?

Answer : How can I get an accurate age to display in an Access form?

Relative to the exact MDB I just down loaded:

1) In text box txtAge1,  *remove* the yy in the Format property.

2) Make this the control source (same expression we have been using):

=DateDiff("yyyy",[txtDOB1],Date())+(Month(Date())[txtDOB1]))

The age now displays correctly.

Example:

Navigate using the Nav window at the bottom to record # 10453 (mailing list ID 10907)
DOB = 5-27-1957    Age displays 50.  Test some other records.

NOTE: Prior to me making this change, because txtAge1's width was narrow AND having the Format set ot yy  ... what you were actually seeing on this record was 04-26-1950 ... and just the 50 was displaying. When you click into the text box , you can see an entire date (instead of an age).

So,  in summary .... make these changes.  Again, keep in mind ... the function above is not perfect (issue with Feb29).  If you want the ultimate Age function, the use gustav's code ...  and then place

=IIf([DOB1] Is Null,Null,Age([DOB1];Date()))  

in the control source for txtDOB1.

mx

Random Solutions  
 
programming4us programming4us