G
george
Hi,
I've copied the following code from the microsoft access
mvp organization site.
'--- CODE START ---
Public Sub CalcAge(vDate1 As Date, vdate2 As Date, ByRef
vYears As Integer,
ByRef vMonths As Integer, ByRef vDays As Integer)
' Comments : calculates the age in Years, Months and
Days
' Parameters:
' vDate1 - D.O.B.
' vDate2 - Date to calculate age based on
' vYears - will hold the Years difference
' vMonths - will hold the Months difference
' vDays - will hold the Days difference
vMonths = DateDiff("m", vDate1, vdate2)
vDays = DateDiff("d", DateAdd("m", vMonths, vDate1),
vdate2)
If vDays < 0 Then
' wierd way that DateDiff works, fix it here
vMonths = vMonths - 1
vDays = DateDiff("d", DateAdd("m", vMonths,
vDate1), vdate2)
End If
vYears = vMonths \ 12 ' integer division
vMonths = vMonths Mod 12 ' only want leftover less
than one year
End Sub
'--- CODE END ---
Can someone help me on how to use it? I have a clients
form with a textbox, ClientBirthdate, on it and another
textbox, ClientAge. What do I need to do to display the
client's age in the corresponding textbox?
thanks in advance, george
I've copied the following code from the microsoft access
mvp organization site.
'--- CODE START ---
Public Sub CalcAge(vDate1 As Date, vdate2 As Date, ByRef
vYears As Integer,
ByRef vMonths As Integer, ByRef vDays As Integer)
' Comments : calculates the age in Years, Months and
Days
' Parameters:
' vDate1 - D.O.B.
' vDate2 - Date to calculate age based on
' vYears - will hold the Years difference
' vMonths - will hold the Months difference
' vDays - will hold the Days difference
vMonths = DateDiff("m", vDate1, vdate2)
vDays = DateDiff("d", DateAdd("m", vMonths, vDate1),
vdate2)
If vDays < 0 Then
' wierd way that DateDiff works, fix it here
vMonths = vMonths - 1
vDays = DateDiff("d", DateAdd("m", vMonths,
vDate1), vdate2)
End If
vYears = vMonths \ 12 ' integer division
vMonths = vMonths Mod 12 ' only want leftover less
than one year
End Sub
'--- CODE END ---
Can someone help me on how to use it? I have a clients
form with a textbox, ClientBirthdate, on it and another
textbox, ClientAge. What do I need to do to display the
client's age in the corresponding textbox?
thanks in advance, george