Keeping Calculated Form Fields blank when no input

D

Debbie

From DateCalc (Macropod's), I used the #Days between 2 days formula as he
suggested. It works great. Now a new question:

When the form opens, I use CreateDate as a field and use that as my EndDate.
Then, as StartDate, I enter a Date of Birth. When I calculate the days
using your formula, it works perfectly. BUT, I am allowing up to 4 Dates of
Birth to be entered (with 4 calculations). If there is only 1 entered, the
calculation on the days shows 2009 yrs., 6 months, 20 days (which is today's
date minus 0).

How can I default the calculation tobe blank if no Date of Birth is entered
(which means the field is skipped or tabbed over, not entering spaces in the
field)? I have tried testing for sy=0, sy="", and sy=null, (in addition to
sm and sd using an if statement) but nothing seems to work. Do I need to
preset the variables on the opening of the form, an how? Is there an if
statement to check them all at once?

Thank so much for your help!
 
M

macropod

Hi Debbie,

The simplest way to do this is to select the existing field (you don't need to expand it's code) and press Ctrl-F9 to embed it in a
pair offield braces. It'll look something like: { 2009 yrs., 6 months, 20 days}. Then insert another empty field (Ctrl-F9) on the
left side of the new field and edit the lot to look like: {IF{StartDate \@ YYYY}= 0 "" 2009 yrs., 6 months, 20 days}. Be careful to
preserve the spacing shown to the left of the diplayed age.
 
D

Debbie

Hi Macropod,

I did as you said, exactly, and I understand how the IF statement works.

However, it only works when I put an actual 0 in the Date of Birth field,
which houses my StartDate bookmark. When I blank out the date (after it was
already filled in) or tab over the field (when opening the template for the
first time), {StartDate \@ YYYY} does not become 0. It appears to become
blank, but not "" or " " because I checked for both individually to see the
results. Both times I got the FALSE reading, even though when I displayed
the variable, it showed a blank.

Apparently, there are other hidden characters in the blank space. Maybe it
is the TAB field itself? I tried figuring out how to insert an ASCII tab,
but I don't know the syntax. I was trying to mimic your {QUOTE 180} from
your DateCalc Document. What would be the equivalent for a tab?

I even tried putting in a hidden field (prior to the input of StartDate) of
SET {StartDate \@ yyyy} 0, and when that didn't work, SET {StartDate} 0 (to
set the whole field to 0), but that took away my bookmark of StartDate at the
Date of Birth field and put it at the SET command and always overrode it to
0, even after I put in the date.

Any thoughts? I know this is very close!
--
Debbie


macropod said:
Hi Debbie,

The simplest way to do this is to select the existing field (you don't need to expand it's code) and press Ctrl-F9 to embed it in a
pair offield braces. It'll look something like: { 2009 yrs., 6 months, 20 days}. Then insert another empty field (Ctrl-F9) on the
left side of the new field and edit the lot to look like: {IF{StartDate \@ YYYY}= 0 "" 2009 yrs., 6 months, 20 days}. Be careful to
preserve the spacing shown to the left of the diplayed age.

--
Cheers
macropod
[Microsoft MVP - Word]


Debbie said:
From DateCalc (Macropod's), I used the #Days between 2 days formula as he
suggested. It works great. Now a new question:

When the form opens, I use CreateDate as a field and use that as my EndDate.
Then, as StartDate, I enter a Date of Birth. When I calculate the days
using your formula, it works perfectly. BUT, I am allowing up to 4 Dates of
Birth to be entered (with 4 calculations). If there is only 1 entered, the
calculation on the days shows 2009 yrs., 6 months, 20 days (which is today's
date minus 0).

How can I default the calculation tobe blank if no Date of Birth is entered
(which means the field is skipped or tabbed over, not entering spaces in the
field)? I have tried testing for sy=0, sy="", and sy=null, (in addition to
sm and sd using an if statement) but nothing seems to work. Do I need to
preset the variables on the opening of the form, an how? Is there an if
statement to check them all at once?

Thank so much for your help!
 
M

macropod

Hi Debbie,

Your empty field probably consists of 5 spaces. In that case, try:
{IF{StartDate}= " " "" 2009 yrs., 6 months, 20 days}
with 5 spaces between the first pair of double quotes.

--
Cheers
macropod
[Microsoft MVP - Word]


Debbie said:
Hi Macropod,

I did as you said, exactly, and I understand how the IF statement works.

However, it only works when I put an actual 0 in the Date of Birth field,
which houses my StartDate bookmark. When I blank out the date (after it was
already filled in) or tab over the field (when opening the template for the
first time), {StartDate \@ YYYY} does not become 0. It appears to become
blank, but not "" or " " because I checked for both individually to see the
results. Both times I got the FALSE reading, even though when I displayed
the variable, it showed a blank.

Apparently, there are other hidden characters in the blank space. Maybe it
is the TAB field itself? I tried figuring out how to insert an ASCII tab,
but I don't know the syntax. I was trying to mimic your {QUOTE 180} from
your DateCalc Document. What would be the equivalent for a tab?

I even tried putting in a hidden field (prior to the input of StartDate) of
SET {StartDate \@ yyyy} 0, and when that didn't work, SET {StartDate} 0 (to
set the whole field to 0), but that took away my bookmark of StartDate at the
Date of Birth field and put it at the SET command and always overrode it to
0, even after I put in the date.

Any thoughts? I know this is very close!
--
Debbie


macropod said:
Hi Debbie,

The simplest way to do this is to select the existing field (you don't need to expand it's code) and press Ctrl-F9 to embed it in
a
pair offield braces. It'll look something like: { 2009 yrs., 6 months, 20 days}. Then insert another empty field (Ctrl-F9) on the
left side of the new field and edit the lot to look like: {IF{StartDate \@ YYYY}= 0 "" 2009 yrs., 6 months, 20 days}. Be careful
to
preserve the spacing shown to the left of the diplayed age.

--
Cheers
macropod
[Microsoft MVP - Word]


Debbie said:
From DateCalc (Macropod's), I used the #Days between 2 days formula as he
suggested. It works great. Now a new question:

When the form opens, I use CreateDate as a field and use that as my EndDate.
Then, as StartDate, I enter a Date of Birth. When I calculate the days
using your formula, it works perfectly. BUT, I am allowing up to 4 Dates of
Birth to be entered (with 4 calculations). If there is only 1 entered, the
calculation on the days shows 2009 yrs., 6 months, 20 days (which is today's
date minus 0).

How can I default the calculation tobe blank if no Date of Birth is entered
(which means the field is skipped or tabbed over, not entering spaces in the
field)? I have tried testing for sy=0, sy="", and sy=null, (in addition to
sm and sd using an if statement) but nothing seems to work. Do I need to
preset the variables on the opening of the form, an how? Is there an if
statement to check them all at once?

Thank so much for your help!
 
S

Suzanne S. Barnhill

An empty text form field actually contains five nonbreaking spaces, so when
you test it for emptiness, you must compare to that. I've sometimes had
success actually typing the spaces into the IF field, but it works better if
I copy/paste the spaces from the form field.

I don't know if this is your situation, since I haven't been following the
entire thread, but if the form field is "empty," then this might help.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org

Debbie said:
Hi Macropod,

I did as you said, exactly, and I understand how the IF statement works.

However, it only works when I put an actual 0 in the Date of Birth field,
which houses my StartDate bookmark. When I blank out the date (after it
was
already filled in) or tab over the field (when opening the template for
the
first time), {StartDate \@ YYYY} does not become 0. It appears to become
blank, but not "" or " " because I checked for both individually to see
the
results. Both times I got the FALSE reading, even though when I displayed
the variable, it showed a blank.

Apparently, there are other hidden characters in the blank space. Maybe
it
is the TAB field itself? I tried figuring out how to insert an ASCII tab,
but I don't know the syntax. I was trying to mimic your {QUOTE 180} from
your DateCalc Document. What would be the equivalent for a tab?

I even tried putting in a hidden field (prior to the input of StartDate)
of
SET {StartDate \@ yyyy} 0, and when that didn't work, SET {StartDate} 0
(to
set the whole field to 0), but that took away my bookmark of StartDate at
the
Date of Birth field and put it at the SET command and always overrode it
to
0, even after I put in the date.

Any thoughts? I know this is very close!
--
Debbie


macropod said:
Hi Debbie,

The simplest way to do this is to select the existing field (you don't
need to expand it's code) and press Ctrl-F9 to embed it in a
pair offield braces. It'll look something like: { 2009 yrs., 6 months, 20
days}. Then insert another empty field (Ctrl-F9) on the
left side of the new field and edit the lot to look like: {IF{StartDate
\@ YYYY}= 0 "" 2009 yrs., 6 months, 20 days}. Be careful to
preserve the spacing shown to the left of the diplayed age.

--
Cheers
macropod
[Microsoft MVP - Word]


Debbie said:
From DateCalc (Macropod's), I used the #Days between 2 days formula as
he
suggested. It works great. Now a new question:

When the form opens, I use CreateDate as a field and use that as my
EndDate.
Then, as StartDate, I enter a Date of Birth. When I calculate the days
using your formula, it works perfectly. BUT, I am allowing up to 4
Dates of
Birth to be entered (with 4 calculations). If there is only 1 entered,
the
calculation on the days shows 2009 yrs., 6 months, 20 days (which is
today's
date minus 0).

How can I default the calculation tobe blank if no Date of Birth is
entered
(which means the field is skipped or tabbed over, not entering spaces
in the
field)? I have tried testing for sy=0, sy="", and sy=null, (in
addition to
sm and sd using an if statement) but nothing seems to work. Do I need
to
preset the variables on the opening of the form, an how? Is there an
if
statement to check them all at once?

Thank so much for your help!
 
D

Debbie

Thank you both Macropod and Suzanne. I really appreciate all your help.

Your answers were perfect! 5 spaces did the trick. Everything is almost in
place. Just one more question (hopefully!)

I ended up using "Calculate the # Years Months & Days Difference Between Two
Dates" because the Years, Months, Days format was more appropriate. Now I
would like to simply take that calculated date (let's say it was 5 yrs. 3 mo.
12 days) and subtract it from 18 years, 0 mo. 0 days. Days are actually
unnecessary for this calculation; I am just looking at years and months. If
they are older than 18 years, I would want blanks in the field. The answer,
in this case, would be 12 years, 9 months. Can you please help me write this
formula?

When using decimals, as I previously tried but decided not to do, that was
easy. I don't think this is that easy.

Thanks again!

I decided to use the
--
Debbie


macropod said:
Hi Debbie,

Your empty field probably consists of 5 spaces. In that case, try:
{IF{StartDate}= " " "" 2009 yrs., 6 months, 20 days}
with 5 spaces between the first pair of double quotes.

--
Cheers
macropod
[Microsoft MVP - Word]


Debbie said:
Hi Macropod,

I did as you said, exactly, and I understand how the IF statement works.

However, it only works when I put an actual 0 in the Date of Birth field,
which houses my StartDate bookmark. When I blank out the date (after it was
already filled in) or tab over the field (when opening the template for the
first time), {StartDate \@ YYYY} does not become 0. It appears to become
blank, but not "" or " " because I checked for both individually to see the
results. Both times I got the FALSE reading, even though when I displayed
the variable, it showed a blank.

Apparently, there are other hidden characters in the blank space. Maybe it
is the TAB field itself? I tried figuring out how to insert an ASCII tab,
but I don't know the syntax. I was trying to mimic your {QUOTE 180} from
your DateCalc Document. What would be the equivalent for a tab?

I even tried putting in a hidden field (prior to the input of StartDate) of
SET {StartDate \@ yyyy} 0, and when that didn't work, SET {StartDate} 0 (to
set the whole field to 0), but that took away my bookmark of StartDate at the
Date of Birth field and put it at the SET command and always overrode it to
0, even after I put in the date.

Any thoughts? I know this is very close!
--
Debbie


macropod said:
Hi Debbie,

The simplest way to do this is to select the existing field (you don't need to expand it's code) and press Ctrl-F9 to embed it in
a
pair offield braces. It'll look something like: { 2009 yrs., 6 months, 20 days}. Then insert another empty field (Ctrl-F9) on the
left side of the new field and edit the lot to look like: {IF{StartDate \@ YYYY}= 0 "" 2009 yrs., 6 months, 20 days}. Be careful
to
preserve the spacing shown to the left of the diplayed age.

--
Cheers
macropod
[Microsoft MVP - Word]


From DateCalc (Macropod's), I used the #Days between 2 days formula as he
suggested. It works great. Now a new question:

When the form opens, I use CreateDate as a field and use that as my EndDate.
Then, as StartDate, I enter a Date of Birth. When I calculate the days
using your formula, it works perfectly. BUT, I am allowing up to 4 Dates of
Birth to be entered (with 4 calculations). If there is only 1 entered, the
calculation on the days shows 2009 yrs., 6 months, 20 days (which is today's
date minus 0).

How can I default the calculation tobe blank if no Date of Birth is entered
(which means the field is skipped or tabbed over, not entering spaces in the
field)? I have tried testing for sy=0, sy="", and sy=null, (in addition to
sm and sd using an if statement) but nothing seems to work. Do I need to
preset the variables on the opening of the form, an how? Is there an if
statement to check them all at once?

Thank so much for your help!
 
M

macropod

Hi Debbie,
When using decimals, as I previously tried but decided not to do, that was
easy. I don't think this is that easy.
ROFL!

Too right it's not that easy:
{QUOTE
{ASK Startdate}
{SET EndDate {DATE}}
{SET ey{={StartDate \@ yyyy}+18}}
{SET em{={StartDate \@ MM}}}
{SET ed{={StartDate \@ d}-({StartDate \@ d}>28)*({StartDate \@ M}=2)*((MOD(yy,4)>0)+(MOD(yy,400)>0)-(MOD(yy,100)>0))}}
{SET sy{EndDate \@ yyyy}}
{SET sm{EndDate \@ M}}
{SET sd{EndDate \@ d}}
{SET md{=IF((em=2),28+(em=2)*((MOD(ey,4)=0)+(MOD(ey,400)=0)-(MOD(ey,100)=0)),31-((em=4)+(em=6)+(em=9)+(em=11)))}}
{Set Years{=ey-sy-(em<sm)-(em=sm)*(ed<sd)}}
{Set Months{=MOD(12+em-sm-(ed<sd),12) \# 0}}
{Set Days{=MOD(md+ed-sd,md) \# 0}}
{IF{={Years}*10000+{Months}*100+{Days}}= 0 "Age 18 today!" {IF{Years}< 0 "Over age 18" "{Years} Year{IF{Years}= 1 "" s}, {Months}
Month{IF{Months}= 1 "" s}, {Days} Day{IF{Days}= 1 "" s} till age 18."}}}
Most of the code for the above is borrowed from the 'Calculate the # Years Months & Days Difference Between Two Dates' and
'Calculate a day, date, month and year, using n years delay' examples in the tutorial. Note, though, that I've swapped the 'ey',
'em' and 'ey' variable designations with their 'sy', 'sm' and 'sy' equivalents. The other significant change is the addition of two
more IF tests governing the output.

Note that any additional field braces (ie '{}') must be created by Ctrl-F9 - you can't type them in or copy & paste them from this
message.

--
Cheers
macropod
[Microsoft MVP - Word]


Debbie said:
Thank you both Macropod and Suzanne. I really appreciate all your help.

Your answers were perfect! 5 spaces did the trick. Everything is almost in
place. Just one more question (hopefully!)

I ended up using "Calculate the # Years Months & Days Difference Between Two
Dates" because the Years, Months, Days format was more appropriate. Now I
would like to simply take that calculated date (let's say it was 5 yrs. 3 mo.
12 days) and subtract it from 18 years, 0 mo. 0 days. Days are actually
unnecessary for this calculation; I am just looking at years and months. If
they are older than 18 years, I would want blanks in the field. The answer,
in this case, would be 12 years, 9 months. Can you please help me write this
formula?

When using decimals, as I previously tried but decided not to do, that was
easy. I don't think this is that easy.

Thanks again!

I decided to use the
--
Debbie


macropod said:
Hi Debbie,

Your empty field probably consists of 5 spaces. In that case, try:
{IF{StartDate}= " " "" 2009 yrs., 6 months, 20 days}
with 5 spaces between the first pair of double quotes.

--
Cheers
macropod
[Microsoft MVP - Word]


Debbie said:
Hi Macropod,

I did as you said, exactly, and I understand how the IF statement works.

However, it only works when I put an actual 0 in the Date of Birth field,
which houses my StartDate bookmark. When I blank out the date (after it was
already filled in) or tab over the field (when opening the template for the
first time), {StartDate \@ YYYY} does not become 0. It appears to become
blank, but not "" or " " because I checked for both individually to see the
results. Both times I got the FALSE reading, even though when I displayed
the variable, it showed a blank.

Apparently, there are other hidden characters in the blank space. Maybe it
is the TAB field itself? I tried figuring out how to insert an ASCII tab,
but I don't know the syntax. I was trying to mimic your {QUOTE 180} from
your DateCalc Document. What would be the equivalent for a tab?

I even tried putting in a hidden field (prior to the input of StartDate) of
SET {StartDate \@ yyyy} 0, and when that didn't work, SET {StartDate} 0 (to
set the whole field to 0), but that took away my bookmark of StartDate at the
Date of Birth field and put it at the SET command and always overrode it to
0, even after I put in the date.

Any thoughts? I know this is very close!
--
Debbie


:

Hi Debbie,

The simplest way to do this is to select the existing field (you don't need to expand it's code) and press Ctrl-F9 to embed it
in
a
pair offield braces. It'll look something like: { 2009 yrs., 6 months, 20 days}. Then insert another empty field (Ctrl-F9) on
the
left side of the new field and edit the lot to look like: {IF{StartDate \@ YYYY}= 0 "" 2009 yrs., 6 months, 20 days}. Be
careful
to
preserve the spacing shown to the left of the diplayed age.

--
Cheers
macropod
[Microsoft MVP - Word]


From DateCalc (Macropod's), I used the #Days between 2 days formula as he
suggested. It works great. Now a new question:

When the form opens, I use CreateDate as a field and use that as my EndDate.
Then, as StartDate, I enter a Date of Birth. When I calculate the days
using your formula, it works perfectly. BUT, I am allowing up to 4 Dates of
Birth to be entered (with 4 calculations). If there is only 1 entered, the
calculation on the days shows 2009 yrs., 6 months, 20 days (which is today's
date minus 0).

How can I default the calculation tobe blank if no Date of Birth is entered
(which means the field is skipped or tabbed over, not entering spaces in the
field)? I have tried testing for sy=0, sy="", and sy=null, (in addition to
sm and sd using an if statement) but nothing seems to work. Do I need to
preset the variables on the opening of the form, an how? Is there an if
statement to check them all at once?

Thank so much for your help!
 
M

macropod

PS:
The two fields:
{ASK Startdate}
{SET EndDate {DATE}}
are just for testing without protecting the form - you should delete them before applying the protection.

--
Cheers
macropod
[Microsoft MVP - Word]


Debbie said:
Thank you both Macropod and Suzanne. I really appreciate all your help.

Your answers were perfect! 5 spaces did the trick. Everything is almost in
place. Just one more question (hopefully!)

I ended up using "Calculate the # Years Months & Days Difference Between Two
Dates" because the Years, Months, Days format was more appropriate. Now I
would like to simply take that calculated date (let's say it was 5 yrs. 3 mo.
12 days) and subtract it from 18 years, 0 mo. 0 days. Days are actually
unnecessary for this calculation; I am just looking at years and months. If
they are older than 18 years, I would want blanks in the field. The answer,
in this case, would be 12 years, 9 months. Can you please help me write this
formula?

When using decimals, as I previously tried but decided not to do, that was
easy. I don't think this is that easy.

Thanks again!

I decided to use the
--
Debbie


macropod said:
Hi Debbie,

Your empty field probably consists of 5 spaces. In that case, try:
{IF{StartDate}= " " "" 2009 yrs., 6 months, 20 days}
with 5 spaces between the first pair of double quotes.

--
Cheers
macropod
[Microsoft MVP - Word]


Debbie said:
Hi Macropod,

I did as you said, exactly, and I understand how the IF statement works.

However, it only works when I put an actual 0 in the Date of Birth field,
which houses my StartDate bookmark. When I blank out the date (after it was
already filled in) or tab over the field (when opening the template for the
first time), {StartDate \@ YYYY} does not become 0. It appears to become
blank, but not "" or " " because I checked for both individually to see the
results. Both times I got the FALSE reading, even though when I displayed
the variable, it showed a blank.

Apparently, there are other hidden characters in the blank space. Maybe it
is the TAB field itself? I tried figuring out how to insert an ASCII tab,
but I don't know the syntax. I was trying to mimic your {QUOTE 180} from
your DateCalc Document. What would be the equivalent for a tab?

I even tried putting in a hidden field (prior to the input of StartDate) of
SET {StartDate \@ yyyy} 0, and when that didn't work, SET {StartDate} 0 (to
set the whole field to 0), but that took away my bookmark of StartDate at the
Date of Birth field and put it at the SET command and always overrode it to
0, even after I put in the date.

Any thoughts? I know this is very close!
--
Debbie


:

Hi Debbie,

The simplest way to do this is to select the existing field (you don't need to expand it's code) and press Ctrl-F9 to embed it
in
a
pair offield braces. It'll look something like: { 2009 yrs., 6 months, 20 days}. Then insert another empty field (Ctrl-F9) on
the
left side of the new field and edit the lot to look like: {IF{StartDate \@ YYYY}= 0 "" 2009 yrs., 6 months, 20 days}. Be
careful
to
preserve the spacing shown to the left of the diplayed age.

--
Cheers
macropod
[Microsoft MVP - Word]


From DateCalc (Macropod's), I used the #Days between 2 days formula as he
suggested. It works great. Now a new question:

When the form opens, I use CreateDate as a field and use that as my EndDate.
Then, as StartDate, I enter a Date of Birth. When I calculate the days
using your formula, it works perfectly. BUT, I am allowing up to 4 Dates of
Birth to be entered (with 4 calculations). If there is only 1 entered, the
calculation on the days shows 2009 yrs., 6 months, 20 days (which is today's
date minus 0).

How can I default the calculation tobe blank if no Date of Birth is entered
(which means the field is skipped or tabbed over, not entering spaces in the
field)? I have tried testing for sy=0, sy="", and sy=null, (in addition to
sm and sd using an if statement) but nothing seems to work. Do I need to
preset the variables on the opening of the form, an how? Is there an if
statement to check them all at once?

Thank so much for your help!
 
M

macropod

Hi Debbie,

Here's a different version, based on the 'Calculate the # Days Difference Between Two Dates' and 'Calculate a day, date, month and
year, using n years delay' tutorial examples. You might find this better suited to your needs as it rounds off the # months to the
nearest whole month and caters for less than 1/2 a month remaining till the 18th birthday.
{QUOTE
{SET yy{={StartDate \@ yyyy}+18}}
{SET mm{StartDate \@ MM}}
{SET dd{={StartDate \@ d}-({StartDate \@ d}>28)*({StartDate \@ M}=2)*((MOD(yy,4)>0)+(MOD(yy,400)>0)-(MOD(yy,100)>0))}}
{SET Days{={SET a{=INT((14-{mm})/12)}}
{SET b{={yy}+4800-a}}
{SET c{={mm}+12*a-3}}
{SET d{dd}}
{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045}
-
{SET a{=INT((14-{EndDate \@ M})/12)}}
{SET b{={EndDate \@ yyyy}+4800-a}}
{SET c{={EndDate \@ M}+12*a-3}}
{SET d{EndDate \@ d}}
{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045}}}
{SET mmm{=Days/30.436875}}
{SET Months{=MOD(mmm,12) \# 0}}
{SET Years{=INT({=mmm}/12)}}
{IF{Days}> 0 "{IF{Years}> 0 "{Years} Year{IF{Years}<> 1 s}, "}{IF{Months}> 0 "{Months} Month{IF{Months}<> 1 s}" "Less than 1 month"}
until age 18." {=Days \# ";Already over age 18.;18 today!"}}}


--
Cheers
macropod
[Microsoft MVP - Word]


Debbie said:
Thank you both Macropod and Suzanne. I really appreciate all your help.

Your answers were perfect! 5 spaces did the trick. Everything is almost in
place. Just one more question (hopefully!)

I ended up using "Calculate the # Years Months & Days Difference Between Two
Dates" because the Years, Months, Days format was more appropriate. Now I
would like to simply take that calculated date (let's say it was 5 yrs. 3 mo.
12 days) and subtract it from 18 years, 0 mo. 0 days. Days are actually
unnecessary for this calculation; I am just looking at years and months. If
they are older than 18 years, I would want blanks in the field. The answer,
in this case, would be 12 years, 9 months. Can you please help me write this
formula?

When using decimals, as I previously tried but decided not to do, that was
easy. I don't think this is that easy.

Thanks again!

I decided to use the
--
Debbie


macropod said:
Hi Debbie,

Your empty field probably consists of 5 spaces. In that case, try:
{IF{StartDate}= " " "" 2009 yrs., 6 months, 20 days}
with 5 spaces between the first pair of double quotes.

--
Cheers
macropod
[Microsoft MVP - Word]


Debbie said:
Hi Macropod,

I did as you said, exactly, and I understand how the IF statement works.

However, it only works when I put an actual 0 in the Date of Birth field,
which houses my StartDate bookmark. When I blank out the date (after it was
already filled in) or tab over the field (when opening the template for the
first time), {StartDate \@ YYYY} does not become 0. It appears to become
blank, but not "" or " " because I checked for both individually to see the
results. Both times I got the FALSE reading, even though when I displayed
the variable, it showed a blank.

Apparently, there are other hidden characters in the blank space. Maybe it
is the TAB field itself? I tried figuring out how to insert an ASCII tab,
but I don't know the syntax. I was trying to mimic your {QUOTE 180} from
your DateCalc Document. What would be the equivalent for a tab?

I even tried putting in a hidden field (prior to the input of StartDate) of
SET {StartDate \@ yyyy} 0, and when that didn't work, SET {StartDate} 0 (to
set the whole field to 0), but that took away my bookmark of StartDate at the
Date of Birth field and put it at the SET command and always overrode it to
0, even after I put in the date.

Any thoughts? I know this is very close!
--
Debbie


:

Hi Debbie,

The simplest way to do this is to select the existing field (you don't need to expand it's code) and press Ctrl-F9 to embed it
in
a
pair offield braces. It'll look something like: { 2009 yrs., 6 months, 20 days}. Then insert another empty field (Ctrl-F9) on
the
left side of the new field and edit the lot to look like: {IF{StartDate \@ YYYY}= 0 "" 2009 yrs., 6 months, 20 days}. Be
careful
to
preserve the spacing shown to the left of the diplayed age.

--
Cheers
macropod
[Microsoft MVP - Word]


From DateCalc (Macropod's), I used the #Days between 2 days formula as he
suggested. It works great. Now a new question:

When the form opens, I use CreateDate as a field and use that as my EndDate.
Then, as StartDate, I enter a Date of Birth. When I calculate the days
using your formula, it works perfectly. BUT, I am allowing up to 4 Dates of
Birth to be entered (with 4 calculations). If there is only 1 entered, the
calculation on the days shows 2009 yrs., 6 months, 20 days (which is today's
date minus 0).

How can I default the calculation tobe blank if no Date of Birth is entered
(which means the field is skipped or tabbed over, not entering spaces in the
field)? I have tried testing for sy=0, sy="", and sy=null, (in addition to
sm and sd using an if statement) but nothing seems to work. Do I need to
preset the variables on the opening of the form, an how? Is there an if
statement to check them all at once?

Thank so much for your help!
 
D

Debbie

Macropod,

You are simply amazing. Thanks so much for all your help. I have been on
vacation and am just about to embark on trying to implement what you gave me.
Thanks again!

--
Debbie


macropod said:
Hi Debbie,

Here's a different version, based on the 'Calculate the # Days Difference Between Two Dates' and 'Calculate a day, date, month and
year, using n years delay' tutorial examples. You might find this better suited to your needs as it rounds off the # months to the
nearest whole month and caters for less than 1/2 a month remaining till the 18th birthday.
{QUOTE
{SET yy{={StartDate \@ yyyy}+18}}
{SET mm{StartDate \@ MM}}
{SET dd{={StartDate \@ d}-({StartDate \@ d}>28)*({StartDate \@ M}=2)*((MOD(yy,4)>0)+(MOD(yy,400)>0)-(MOD(yy,100)>0))}}
{SET Days{={SET a{=INT((14-{mm})/12)}}
{SET b{={yy}+4800-a}}
{SET c{={mm}+12*a-3}}
{SET d{dd}}
{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045}
-
{SET a{=INT((14-{EndDate \@ M})/12)}}
{SET b{={EndDate \@ yyyy}+4800-a}}
{SET c{={EndDate \@ M}+12*a-3}}
{SET d{EndDate \@ d}}
{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045}}}
{SET mmm{=Days/30.436875}}
{SET Months{=MOD(mmm,12) \# 0}}
{SET Years{=INT({=mmm}/12)}}
{IF{Days}> 0 "{IF{Years}> 0 "{Years} Year{IF{Years}<> 1 s}, "}{IF{Months}> 0 "{Months} Month{IF{Months}<> 1 s}" "Less than 1 month"}
until age 18." {=Days \# ";Already over age 18.;18 today!"}}}


--
Cheers
macropod
[Microsoft MVP - Word]


Debbie said:
Thank you both Macropod and Suzanne. I really appreciate all your help.

Your answers were perfect! 5 spaces did the trick. Everything is almost in
place. Just one more question (hopefully!)

I ended up using "Calculate the # Years Months & Days Difference Between Two
Dates" because the Years, Months, Days format was more appropriate. Now I
would like to simply take that calculated date (let's say it was 5 yrs. 3 mo.
12 days) and subtract it from 18 years, 0 mo. 0 days. Days are actually
unnecessary for this calculation; I am just looking at years and months. If
they are older than 18 years, I would want blanks in the field. The answer,
in this case, would be 12 years, 9 months. Can you please help me write this
formula?

When using decimals, as I previously tried but decided not to do, that was
easy. I don't think this is that easy.

Thanks again!

I decided to use the
--
Debbie


macropod said:
Hi Debbie,

Your empty field probably consists of 5 spaces. In that case, try:
{IF{StartDate}= " " "" 2009 yrs., 6 months, 20 days}
with 5 spaces between the first pair of double quotes.

--
Cheers
macropod
[Microsoft MVP - Word]


Hi Macropod,

I did as you said, exactly, and I understand how the IF statement works.

However, it only works when I put an actual 0 in the Date of Birth field,
which houses my StartDate bookmark. When I blank out the date (after it was
already filled in) or tab over the field (when opening the template for the
first time), {StartDate \@ YYYY} does not become 0. It appears to become
blank, but not "" or " " because I checked for both individually to see the
results. Both times I got the FALSE reading, even though when I displayed
the variable, it showed a blank.

Apparently, there are other hidden characters in the blank space. Maybe it
is the TAB field itself? I tried figuring out how to insert an ASCII tab,
but I don't know the syntax. I was trying to mimic your {QUOTE 180} from
your DateCalc Document. What would be the equivalent for a tab?

I even tried putting in a hidden field (prior to the input of StartDate) of
SET {StartDate \@ yyyy} 0, and when that didn't work, SET {StartDate} 0 (to
set the whole field to 0), but that took away my bookmark of StartDate at the
Date of Birth field and put it at the SET command and always overrode it to
0, even after I put in the date.

Any thoughts? I know this is very close!
--
Debbie


:

Hi Debbie,

The simplest way to do this is to select the existing field (you don't need to expand it's code) and press Ctrl-F9 to embed it
in
a
pair offield braces. It'll look something like: { 2009 yrs., 6 months, 20 days}. Then insert another empty field (Ctrl-F9) on
the
left side of the new field and edit the lot to look like: {IF{StartDate \@ YYYY}= 0 "" 2009 yrs., 6 months, 20 days}. Be
careful
to
preserve the spacing shown to the left of the diplayed age.

--
Cheers
macropod
[Microsoft MVP - Word]


From DateCalc (Macropod's), I used the #Days between 2 days formula as he
suggested. It works great. Now a new question:

When the form opens, I use CreateDate as a field and use that as my EndDate.
Then, as StartDate, I enter a Date of Birth. When I calculate the days
using your formula, it works perfectly. BUT, I am allowing up to 4 Dates of
Birth to be entered (with 4 calculations). If there is only 1 entered, the
calculation on the days shows 2009 yrs., 6 months, 20 days (which is today's
date minus 0).

How can I default the calculation tobe blank if no Date of Birth is entered
(which means the field is skipped or tabbed over, not entering spaces in the
field)? I have tried testing for sy=0, sy="", and sy=null, (in addition to
sm and sd using an if statement) but nothing seems to work. Do I need to
preset the variables on the opening of the form, an how? Is there an if
statement to check them all at once?

Thank so much for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top