Thread: Calculate Age as of August 1

1. Registered User
Join Date
Sep 2004
Posts
11

Unanswered: Calculate Age as of August 1

I have a membership database where I need to calculate the age of a person as of August 1 of each year. The age of the person would stay the same until the following August 1 where it would adjust age to next year.

2. Moderator
Join Date
Jun 2005
Location
Richmond, Virginia USA
Posts
2,764
This should do it for you, where DOB_Field is the actual name of the field you have the date of birth in:
Code:
```Private Sub DOB_Field_AfterUpdate()
If Not IsNull(Me.DOB_Field) Then
Me.AgeAsOfAugust = DateDiff("yyyy", [DOB_Field], DateSerial(Year(Date), 8, 1)) - IIf(Format\$(DateSerial(Year(Date), 8, 1), "mmdd") < Format\$([DOB_Field], "mmdd"), 1, 0)
End If
End Sub

Private Sub Form_Current()
If Not IsNull(Me.DOB_Field) Then
Me.AgeAsOfAugust = DateDiff("yyyy", [DOB_Field], DateSerial(Year(Date), 8, 1)) - IIf(Format\$(DateSerial(Year(Date), 8, 1), "mmdd") < Format\$([DOB_Field], "mmdd"), 1, 0)
End If
End Sub```
Linq ;0)>

3. Moderator
Join Date
Jun 2005
Location
Richmond, Virginia USA
Posts
2,764
This should do it for you, where DOB_Field is the actual name of the field you have the date of birth in and AgeAsOfAugust is the name of your unbound textbox:
Code:
```Private Sub DOB_Field_AfterUpdate()
If Not IsNull(Me.DOB_Field) Then
Me.AgeAsOfAugust = DateDiff("yyyy", [DOB_Field], DateSerial(Year(Date), 8, 1)) - IIf(Format\$(DateSerial(Year(Date), 8, 1), "mmdd") < Format\$([DOB_Field], "mmdd"), 1, 0)
End If
End Sub

Private Sub Form_Current()
If Not IsNull(Me.DOB_Field) Then
Me.AgeAsOfAugust = DateDiff("yyyy", [DOB_Field], DateSerial(Year(Date), 8, 1)) - IIf(Format\$(DateSerial(Year(Date), 8, 1), "mmdd") < Format\$([DOB_Field], "mmdd"), 1, 0)
End If
End Sub```
Linq ;0)>

Sorry! Don't know why an edit double-posted!