Code: Select all
Private Sub txtDateOfBirth_AfterUpdate()
Dim Period As String
If Not IsDate(Me.txtDateofBirth.Value) Then
MsgBox "The Date box must contain a date.", vbExclamation, "Add New Customer"
Me.txtAge = ""
Else
Me.txtAge = AgeCalc(CDate(Me.txtDateofBirth), Period) & Chr(32) & Period
End If
End Sub
Function AgeCalc(DOB As Date, Period As String) As Long
Select Case Date - DOB
Case Is > 365
AgeCalc = Int((Date - DOB) / 365)
Period = IIf(AgeCalc >= 2, "Years", "Year")
Case Is > 30
AgeCalc = Int((Date - DOB) / 30)
Period = IIf(AgeCalc >= 2, "Months", "Month")
Case Is > 7
AgeCalc = Int((Date - DOB) / 7)
Period = IIf(AgeCalc >= 2, "Weeks", "Week")
Case Else
AgeCalc = Date - DOB
Period = IIf(AgeCalc >= 2, "Days", "Day")
End Select
End Function
Any help on this wold be kindly appreciated.
Thanks in advance.