I have a word document that I uses a Bookmarked Text Form Field to calculate the age, in years, based on the current date. When the Text Form Field is empty, the field code returns the current year. I'd like it to return no text when the bookmarked form field is empty.
The Text Form Field type is 'Date' formatted as M/d/yyyy and bookmarked as 'DOB'
Here is the field code I have to calculate the age:
{QUOTE{SET by {DOB \@ yyyy}}
{SET bm {DOB \@ M}}
{SET bd {DOB \@ d}}
{SET yy {DATE \@ yyyy}}
{SET mm {DATE \@ M}}
{SET dd {DATE \@ d}}
{Set Years {=yy-by-(mm<bm)-(mm=bm)*(dd<bd) \# 0}}
{IF {DOB}= “” “” {Years}}
To my understanding when the bookmarked Text Form Field does not contain text, the field it not technically 'empty' or blank and so my last line of field code with the IF functions does not work.
I need help to make that code return a blank or empty field when the Text Form Field is not filled in.
What syntax is contained in an empty Text Form Field?
I suggest you test DOB at the beginning, like this:
{IF {DOB} = " " "" "{SET by {DOB \@ yyyy}}{SET bm {DOB \@ M}}{SET bd {DOB \@ d}}{SET yy {DATE \@ yyyy}}{SET mm {DATE \@ M}}{SET dd {DATE \@ d}}{=yy-by-(mm<bm)-(mm=bm)*(dd<bd) \#0}"}
(I leave you to re-organize that to fit your layout preferences)
...where the characters between the quotation marks in this part IF {DOB} = " "
are just regular spaces.
As background, if you use VBA to check the character code that Word actually displays in an empty text form field, it's a U+2002 (decimal 8194), which is a Unicode n-space character. I think in much older versions of Word it was probably a non-breaking space character (ASCII decimal 160). However, you can enter 5 spaces of several types into the Form Field (m-spaces, n-spaces, ordinary spaces, non-breaking spaces, I haven't checked them all) and they all match a 5-space literal.
So in the case where you actually need to distinguish between the user entering 5 regular spaces and leaving the form field empty, this test is not enough. But because you have formatted the field as a date, AFAIK the only options are to leave the field empty or enter a valid date, so there is no real confusion even if the user could enter 5 ordinary spaces.