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

RE: calculating age in word xp by alborg

alborg
Tue Oct 16 20:23:02 PDT 2007

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

"ribspreader" wrote:

> 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

RE: calculating age in word xp by ribspreader

ribspreader
Wed Oct 17 07:54:07 PDT 2007

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?

"alborg" wrote:

> 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
>
> "ribspreader" wrote:
>
> > 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

RE: calculating age in word xp by alborg

alborg
Wed Oct 17 22:43:02 PDT 2007

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

"ribspreader" wrote:

> 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?
>
> "alborg" wrote:
>
> > 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
> >
> > "ribspreader" wrote:
> >
> > > 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

Re: calculating age in word xp by Graham

Graham
Wed Oct 17 23:18:35 PDT 2007

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

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

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

ribspreader wrote:
> 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?
>
> "alborg" wrote:
>
>> 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
>>
>> "ribspreader" wrote:
>>
>>> 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



Re: calculating age in word xp by Graham

Graham
Wed Oct 17 23:23:02 PDT 2007

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!"}}

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

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


ribspreader wrote:
> 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?
>
> "alborg" wrote:
>
>> 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
>>
>> "ribspreader" wrote:
>>
>>> 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



Re: calculating age in word xp by alborg

alborg
Thu Oct 18 01:50:01 PDT 2007

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

"Graham Mayor" wrote:

> 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!"}}
>
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - Word MVP
>
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
>
> ribspreader wrote:
> > 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?
> >
> > "alborg" wrote:
> >
> >> 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
> >>
> >> "ribspreader" wrote:
> >>
> >>> 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
>
>
>

Re: calculating age in word xp by Graham

Graham
Thu Oct 18 04:24:14 PDT 2007

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.

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

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

alborg wrote:
> 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
>
> "Graham Mayor" wrote:
>
>> 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 "