Calculating age from Date of Birth

Shazz

Registered User.
Local time
Yesterday, 20:44
Joined
Oct 14, 2008
Messages
53
I wonder if anyone can help, I have a dateabase which I want to be able to calculate the age from the Date of Birth field, can anyone help me, please keep it simple as I have no knowlegdge of this kind of thing in Access.

Thanks

Shazz
 
Assuming your date of birth field is named DOBField and your field for the current age is AgeToday:

To calculate the first time:
Code:
Private Sub DOBField_AfterUpdate()
  Me.AgeToday = DateDiff("yyyy", [DOBField], Date) - IIf(Format$(Date, "mmdd") < Format$([DOBField], "mmdd"), 1, 0)
End Sub

To calculate it each time the record is accessed:
Code:
Private Sub Form_Current()
If Not IsNull(Me.DOBField) Then
  Me.AgeToday = DateDiff("yyyy", [DOBField], Date) - IIf(Format$(Date, "mmdd") < Format$([DOBField], "mmdd"), 1, 0)
End If
End Sub
 
Very useful Code, thanks very much for the BIG HELP:)
 

Users who are viewing this thread

Back
Top Bottom