A
aneasiertomorrow
Hi all
Firstly, apologies for posting twice but I suddenly realised the thread I
posted to was quite old so people might not spot it...
I want to add a Text Form Field to my form that displays someone's age in
years and months after they add their dob to another field. I found this
response from Graham Mayor and have manged to make it display in months
instead of years but don't now how to make that years and months. I know the
formula in Excel if that helps. Oh and the wopr site is down so I can't read
the suggested article/thread.
I'm a VBA newbie barely beyond copying & pasting code I find on these
discussion groups
Here's Graham's post:
Assuming the date is entered in field Text1, the following macro run on exit
from text 1 will put the age in field Text2
Sub CalculateDiff()
Dim sDate As String
Dim vDiff As Variant
Dim sResult As String
sDate = ActiveDocument.FormFields("Text1").Result
sDate = Format(sDate, "d m yy")
If sDate <> "" Then
If Not IsDate(sDate) Then
Debug.Print "Not a valid date!"
Else
vDiff = DateDiff("m", CDate(sDate), Format(Date, "d m yy"))
If vDiff Mod 12 >= 6 Then
sResult = CStr(CInt((vDiff / 12)) + 1)
MsgBox "Difference in years is almost " & sResult
Else
sResult = CStr(CInt(vDiff / 12))
ActiveDocument.FormFields("Text2").Result = sResult
End If
End If
End If
End Sub
You should also be able to do this with calculated fields, albeit it is far
more complicated and you will need the samples from
www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902
Thanks
Lucy
--
MOS Master Instructor
www.aneasiertomorrow.com.au
PowerPoint Live 2007 28-31 October in New Orleans www.pptlive.com
See you there
Firstly, apologies for posting twice but I suddenly realised the thread I
posted to was quite old so people might not spot it...
I want to add a Text Form Field to my form that displays someone's age in
years and months after they add their dob to another field. I found this
response from Graham Mayor and have manged to make it display in months
instead of years but don't now how to make that years and months. I know the
formula in Excel if that helps. Oh and the wopr site is down so I can't read
the suggested article/thread.
I'm a VBA newbie barely beyond copying & pasting code I find on these
discussion groups
Here's Graham's post:
Assuming the date is entered in field Text1, the following macro run on exit
from text 1 will put the age in field Text2
Sub CalculateDiff()
Dim sDate As String
Dim vDiff As Variant
Dim sResult As String
sDate = ActiveDocument.FormFields("Text1").Result
sDate = Format(sDate, "d m yy")
If sDate <> "" Then
If Not IsDate(sDate) Then
Debug.Print "Not a valid date!"
Else
vDiff = DateDiff("m", CDate(sDate), Format(Date, "d m yy"))
If vDiff Mod 12 >= 6 Then
sResult = CStr(CInt((vDiff / 12)) + 1)
MsgBox "Difference in years is almost " & sResult
Else
sResult = CStr(CInt(vDiff / 12))
ActiveDocument.FormFields("Text2").Result = sResult
End If
End If
End If
End Sub
You should also be able to do this with calculated fields, albeit it is far
more complicated and you will need the samples from
www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902
Thanks
Lucy
--
MOS Master Instructor
www.aneasiertomorrow.com.au
PowerPoint Live 2007 28-31 October in New Orleans www.pptlive.com
See you there