View Single Post
 
Old 02-09-2017, 02:04 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,343
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You should change your text formfield's internal bookmark name to 'BirthDate' and use a field constructed as:
Code:
{QUOTE
{SET sy{BirthDate \@ yyyy}}
{SET sm{BirthDate \@ M}}
{SET sd{BirthDate \@ d}}
{SET ey{Date \@ yyyy}}
{SET em{Date \@ M}}
{SET ed{Date \@ d}}
{Set Years{=ey-sy-(em<sm)-(em=sm)*(ed<sd)}}
"{Years} Year{IF{Years}= 1 "" s}"}
Do make sure the 'BirthDate' formfield has the 'calculate on exit' property checked.

Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. The spaces represented in the field construction are all required. Although I've used linebreaks in the field code, they're no needed - they just add clarity.

To see how to do just about everything you might want to do with dates in Word, check out my Microsoft Word Date Calculation Tutorial (which is where the above field code comes from):
https://www.msofficeforums.com/word/...-tutorial.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote