Calculating someones age

L

Landor

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
 
T

Tony Williams

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
 

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