I am using Access 2007 and I want to calculate a persons age in years, months
and days on a form. I have a DOB field. Is there an easy formula I can use to
do this? The easier the better as I am new to Access and not that good with
VB, modules etc.
Thanks in anticipation
Landor
Tony Williams - 13 Dec 2007 14:10 GMT
I have a piece of code I use to calculate age and then warn if under 18.You
may be able to adapt this, it foes in the OnEnter event of the control
txtage
Private Sub txtAge_Enter()
Dim dateBirthday As Date
dateBirthday = Date_of_Birth.Value
Dim varAge As Variant
varAge = -DateDiff("yyyy", Date, dateBirthday)
Dim varDiff As Variant
varDiff = DateDiff("d", DateAdd("yyyy", varAge, dateBirthday), Date)
If varDiff < 0 Then
varAge = varAge - 1
End If
txtAge.Value = varAge
If txtAge.Value < 18 Then
MsgBox "This person is under 18!", vbOKOnly, "Warning"
End If
End Sub
HTH
Tony
>I am using Access 2007 and I want to calculate a persons age in years,
>months
[quoted text clipped - 7 lines]
>
> Landor
BruceM - 13 Dec 2007 15:54 GMT
There is some age-calculation code here, if you want to explore other
options:
http://www.mvps.org/access/datetime/date0001.htm
>I am using Access 2007 and I want to calculate a persons age in years,
>months
[quoted text clipped - 7 lines]
>
> Landor