Age in year, day and month

Siegfried

Registered User.
Local time
Today, 06:54
Joined
Sep 11, 2014
Messages
105
Would like to ask your advice, I was trying out following option:

Using following function:
Option Compare Database
Public Function CalcAge(DeliveryDate As Date) As String
Dim intYears As Integer, intMonths As Integer, intDays As Integer
intMonths = DateDiff("m", DeliveryDate, Date)
intDays = DateDiff("d", DateAdd("m", intMonths, DeliveryDate), Date)
If intDays < 0 Then
intMonths = intMonths - 1
intDays = DateDiff("d", DateAdd("m", intMonths, DeliveryDate), Date)
End If
intYears = intMonths \ 12
intMonths = intMonths Mod 12
'CalcAge = intYears & " Years and " & intMonths & " Months And " & intDays & " Days"
CalcAge = intYears & " year" & IIf(intYears = 1, "", "s") & ", " & intMonths & " month" & IIf(intMonths = 1, "", "s") & " and " & intDays & " day" & IIf(intDays = 1, "", "s")
End Function
and created a textbox (Age) on my form Vessel Age and set its ControlSource to: =CalcAge([DOB]).

Form based on TblVessels:
Vesselname - shortext
DeliveryDate - Date/Time short date
However, when I use this function, I'm not getting the age displayed in the textbox the second time I'm opening the form, then the textbox remains empty?
Any idea what's missing here?
Thanks.
 
it is probably calculating the age before the DOB control has been populated

try putting

age.requery

in the form current event
 
That solved the problem. Thanks
 

Users who are viewing this thread

Back
Top Bottom