Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2007

Tip: Looking for answers? Try searching our database.

calculating age in word xp

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ribspreader - 16 Oct 2007 17:12 GMT
i want to list a birthdate on one line and todays date on another, and then
in a third spot have the persons age calculated.  Can anyone tell me how to
do this.  I am new to this and would need step by step instructions. Help
please
alborg - 17 Oct 2007 04:23 GMT
Are you talking about a locked document or a popup UserForm?

There are several ways to calculate the age, the most popular being
something like this:

Function Age(varDOB As Variant)
   Dim varAge As Variant
   If IsNull(varDOB) Then Age = 0: Exit Function
   varAge = DateDiff("yyyy", varDOB, Now)
   If Date < DateSerial(YEAR(Now), Month(varDOB), Day(varDOB)) Then
       varAge = varAge - 1
   End If
   Age = varAge
End Function

Cheers,
Al

> i want to list a birthdate on one line and todays date on another, and then
> in a third spot have the persons age calculated.  Can anyone tell me how to
> do this.  I am new to this and would need step by step instructions. Help
> please
ribspreader - 17 Oct 2007 15:54 GMT
I'm afraid I am clueless about how to input this into a locked document
template.  I created the template, lock it, then dictate and save under a new
name and keep using the original template.  There are several drop down menus
I use, and it automatically inserts todays date in one field.  I want to use
that field, and a Date of Birth field.  How do I get it to use these two
fields, and then how to I input the equations you described?

> Are you talking about a locked document or a popup UserForm?
>
[quoted text clipped - 18 lines]
> > do this.  I am new to this and would need step by step instructions. Help
> > please
alborg - 18 Oct 2007 06:43 GMT
Hi there:

The best way to show the method is to upload a sample template. Check it out
here: http://www.box.net/shared/static/a7acuj88k6.dot

Cheers,
Al

> I'm afraid I am clueless about how to input this into a locked document
> template.  I created the template, lock it, then dictate and save under a new
[quoted text clipped - 25 lines]
> > > do this.  I am new to this and would need step by step instructions. Help
> > > please
Graham Mayor - 18 Oct 2007 07:18 GMT
Calculated date fields are quite complex and do not need vba (though you can
certainly achieve the same ends with vba). If you want to calculate an age
from a DOB field using fields then the construction would be:

{QUOTE
{ASK BirthDate "What is the Birthdate?"}
{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}}
{IF{={IF{={BirthDate \@ "dddd"}}= "!*" 0 1}+{IF{={BirthDate \@ "MMMM"}}=
"!*" 0 1}+{ IF{ by }= "!*" 1 0 }+{IF{BirthDate \@ yyyyMMdd}<{DATE \@
yyyyMMdd} 0 1}}= 0 "If your Date of Birth was {Birthdate \@ "d MMMM yyyy"},
then your age is {Years} Year{IF{Years}= 1 "" s}, {Months} Month{IF{Months}=
1 "" s} and {Days} Day{IF{Days}= 1 "" s}." "Data entry error!"}}

To avoid errors in reproducing this, you can copy the construction from
Macropods excellent article on date fields which you can download from
http://www.gmayor.com/downloads.htm#Third_party

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> I'm afraid I am clueless about how to input this into a locked
> document template.  I created the template, lock it, then dictate and
[quoted text clipped - 26 lines]
>>> anyone tell me how to do this.  I am new to this and would need
>>> step by step instructions. Help please
Graham Mayor - 18 Oct 2007 07:23 GMT
As you are using a formfield to collect the birthdate, you don't need the
ASK field in the example - instead name the Birth Date formfield Birthdate
and set it's type as Date.

Thus

{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}}
{IF{={IF{={BirthDate \@ "dddd"}}= "!*" 0 1}+{IF{={BirthDate \@ "MMMM"}}=
"!*" 0 1}+{ IF{ by }= "!*" 1 0 }+{IF{BirthDate \@ yyyyMMdd}<{DATE \@
yyyyMMdd} 0 1}}= 0 "If your Date of Birth was {Birthdate \@ "d MMMM yyyy"},
then your age is {Years} Year{IF{Years}= 1 "" s}, {Months} Month{IF{Months}=
1 "" s} and {Days} Day{IF{Days}= 1 "" s}." "Data entry error!"}}

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> I'm afraid I am clueless about how to input this into a locked
> document template.  I created the template, lock it, then dictate and
[quoted text clipped - 26 lines]
>>> anyone tell me how to do this.  I am new to this and would need
>>> step by step instructions. Help please
alborg - 18 Oct 2007 09:50 GMT
Hi Graham:

Of the 3 methods that I've encountered over the years, this seems so
complicated! Why not simply use VBA and the DateDiff method? One line does it
all...

Cheers,
Al

> As you are using a formfield to collect the birthdate, you don't need the
> ASK field in the example - instead name the Birth Date formfield Birthdate
[quoted text clipped - 50 lines]
> >>> anyone tell me how to do this.  I am new to this and would need
> >>> step by step instructions. Help please
Graham Mayor - 18 Oct 2007 12:24 GMT
It is not complicated when someone else has already done all the work - just
a matter of copy/paste from the linked document - however I have no issues
with the vba method - I suggested this as an alternative, to show that it
can be done with fields.

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Hi Graham:
>
[quoted text clipped - 68 lines]
>>>>> anyone tell me how to do this.  I am new to this and would need
>>>>> step by step instructions. Help please
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.