calculate in field with date

C

Chey

I have fields in my form and in text53 you type the date of birth. In
another field I want to subtract the current date by text53 to get the
person's age.
How do I write the formula?

Thanks
Cheyenne
 
T

Tony Jollans

You really don't want to know. It is immensely complicated and
incomprehensible to ordinary mortals. MVP macropod has written a document on
the subject but I don't have a handy link. Consider doing the calculations
in a VBA macro, where it is pretty straightforward.
 
C

Chey

I have been messing with that. However I don't know how to intermigle my
field where I type the date into it.

How do I do it in VBA?
 
P

Peter Jamieson

If you want, try this (I have no idea if it will work at all, especially
with a set of fields this complex):

I'm assuming you are using a Word "online form" with form fields that look
like { FORMTEXT } when you display field codes (e.g. using Alt-F9).

Let's suppose you start with just two fields. The field you enter your date
into is called "ed" (in the field properties, which you can access by
right-clicking on the field. Make sure you check "calculate on exit" while
you are in there) and you want to display the calculated date in another
field called "cd"

Set up your "cd" field so that it is a calculated field, and temporaily
insert a calculation such as

=ed

(it won't work properly)

When you unprotect the form and display the field codes, you should now see
something like

{ FORMTEXT } { FORMTEXT {=ed } }

Somewhere else in your document, insert the set of field codes you've worked
out from macropod's article. If it isn't all nested inside a single {
QUOTE } field, which if I remember correctly is macropod's usual approach,
add a { QUOTE } field around the outside.

Select that complete set of fields and paste it into the second FORMTEXT
field so that it replaces {=ed}

Protect your form and see what happens.
 
G

Graham Mayor

The construction for producing age from a date field is

{QUOTE
{SET by {BirthDate \@ yyyy}}
{SET bm {BirthDate \@ M}}
{SET bd {BirthDate \@ d}}
{SET yy {DATE \@ yyyy}}
{SET mm {DATE \@ M}}
{SET dd {DATE \@ d}}
{SET
md{=IF((mm=2),28+(mm=2)*((MOD(yy,4)=0)+(MOD(yy,400)=0)-(MOD(yy,100)=0)),31-((mm=4)+(mm=6)+(mm=9)+(mm=11)))}}
{Set Years{=yy-by-(mm<bm)-(mm=bm)*(dd<bd) \# 0}}
{Set Months{=MOD(12+mm-bm-(dd<bd),12) \# 0}}
{Set Days{=MOD(md+dd-bd,md) \# 0}}
"Your age is {Years} Year{IF{Years}= 1 "" s}, {Months} Month{IF{Months}= 1
"" s} and {Days} Day{IF{Days}= 1 "" s}."}

With the field construction displayed (paste it from Macropod's document),
use Replace to change
BirthDate for Text53 (or better still rename Text53 to BirthDate)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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