Age Calculation in Access
Age Calculation examples are illustrated below. The
first method used the datediff function in the age calculations.
The second tutorial demonstrates the use of the date serial function. Each
example uses today's date - this can be easily switch to a field from you forms
Our programming team has 15 members containing a wide variety of technical database knowledge and programming experience. Experts in small business management and scientific database programming.
Did you know you don't need to move to SQL/Server to run and manage your Access database on the net. There are many alternative solutions. Among them are Amazon's AWS cloud services and various hosting services in nearly every state.
Age Calculation Long Method
Private Sub Birth_Dte_AfterUpdate()
Dim iyears As Integer
Dim tmonth As Integer
Dim Bmonth As Integer
iyears = DateDiff("yyyy", "01/01/" & DatePart("yyyy",
"01/01/" & DatePart("yyyy", Me.Todays_Date)) - 1
tmonth = DatePart("m", Me.Todays_Date)
Bmonth = DatePart("m", Me.Birth_Dte)
Select Case tmonth
Case Is > Bmonth
iyears + 1
Case Is = Bmonth
DatePart("d", Me.Birth_Dte) <= _
Me.Todays_Date) Then iyears = iyears + 1
VBA Age Calculation - Short Method Using Date Serial
Visual Basic Function:
Function age(vb_Dte As Variant)
Dim v_Age_Calc As Variant
v_Age_Calc = DateDiff("yyyy", vb_Dte, Now)
If Date < DateSerial(Year(Now), _
Month(vB_Date), Day(vb_Dte)) Then v_Age_Calc = v_Age_Calc - 1
age = CInt(v_Age_Calc)
Additional information on the
Date Serial function can be found in a VBA Functions tutorial section.
You can also review details about the
in the same section.