Hey Gang,

Word 2003

Trying to create an automated form for my church and am stumped as to how to
do this. I have a calendar form (actually two of them) that populate
formfields (StartDate and EndDate). I have another formfield (TotalDays)
that I cm trying to populate with the number of days difference between the
other two formfields. I assigned the following macro to the "Entry" of the
TotalDays field. However, it is not working.

Sub CalculateTotalDays()
ActiveDocument.FormFields("TotalDays").Result = DateDiff("d", EndDate,
StartDate)
End Sub

I am assuming that Word can't recognize formfields the same way Acces does
to know to use them in the calculation, but I can't seem to find a way to
make it work.

Any ideas? TIA!
--
Bill Foley
Microsoft PowerPoint MVP
Microsoft Office Specialist Master Instructor
www.pttinc.com

Re: Using DateDiff in Formfields... by Graham

Graham
Wed Dec 06 08:57:04 CST 2006

If you don't mind Jezebel's unwarranted scorn, you could do this with a Word
field assembly as opposed to a form field for the result. The construction
is :

{={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
a{=INT((14-{StartDate \@ M})/12)}}{SET b{={StartDate \@ yyyy}+4800-a}}{SET
c{={StartDate \@ M}+12*a-3}}{SET d{StartDate \@
d}}{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045}\# ,0}

www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902 will give you the
source document containing the fields to avoid trying to reconstruct from
here. Don't forget to check the calculate on exit check boxes of the two
date source fields.


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

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



Bill Foley wrote:
> Hey Gang,
>
> Word 2003
>
> Trying to create an automated form for my church and am stumped as to
> how to do this. I have a calendar form (actually two of them) that
> populate formfields (StartDate and EndDate). I have another
> formfield (TotalDays) that I cm trying to populate with the number of
> days difference between the other two formfields. I assigned the
> following macro to the "Entry" of the TotalDays field. However, it
> is not working.
> Sub CalculateTotalDays()
> ActiveDocument.FormFields("TotalDays").Result = DateDiff("d",
> EndDate, StartDate)
> End Sub
>
> I am assuming that Word can't recognize formfields the same way Acces
> does to know to use them in the calculation, but I can't seem to find
> a way to make it work.
>
> Any ideas? TIA!



Re: Using DateDiff in Formfields... by Bill

Bill
Wed Dec 06 09:41:20 CST 2006

Thanks, Graham. I'll give it a go. I'll also hang around for the "correct"
way from Jezebel! HA!

--
Bill Foley
Microsoft PowerPoint MVP
Microsoft Office Specialist Master Instructor
www.pttinc.com
"Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message
news:%230k3LbUGHHA.1240@TK2MSFTNGP03.phx.gbl...
> If you don't mind Jezebel's unwarranted scorn, you could do this with a
> Word field assembly as opposed to a form field for the result. The
> construction is :
>
> {={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
> a{=INT((14-{StartDate \@ M})/12)}}{SET b{={StartDate \@ yyyy}+4800-a}}{SET
> c{={StartDate \@ M}+12*a-3}}{SET d{StartDate \@
> d}}{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045}\# ,0}
>
> www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902 will give you the
> source document containing the fields to avoid trying to reconstruct from
> here. Don't forget to check the calculate on exit check boxes of the two
> date source fields.
>
>
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - Word MVP
>
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
>
>
> Bill Foley wrote:
>> Hey Gang,
>>
>> Word 2003
>>
>> Trying to create an automated form for my church and am stumped as to
>> how to do this. I have a calendar form (actually two of them) that
>> populate formfields (StartDate and EndDate). I have another
>> formfield (TotalDays) that I cm trying to populate with the number of
>> days difference between the other two formfields. I assigned the
>> following macro to the "Entry" of the TotalDays field. However, it
>> is not working.
>> Sub CalculateTotalDays()
>> ActiveDocument.FormFields("TotalDays").Result = DateDiff("d",
>> EndDate, StartDate)
>> End Sub
>>
>> I am assuming that Word can't recognize formfields the same way Acces
>> does to know to use them in the calculation, but I can't seem to find
>> a way to make it work.
>>
>> Any ideas? TIA!
>
>



Re: Using DateDiff in Formfields... by Doug

Doug
Wed Dec 06 09:56:54 CST 2006

ActiveDocument.FormFields("TotalDays").Result = DateDiff("d", EndDate,
StartDate)

Should be:

ActiveDocument.FormFields("TotalDays").Result = DateDiff("d",
ActiveDocument.FormFields("EndDate").Result,
ActiveDocument.FormFields("StartDate").Result)



--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Bill Foley" <pttincatitexasdotnet> wrote in message
news:%23%23c7rMUGHHA.4688@TK2MSFTNGP04.phx.gbl...
> Hey Gang,
>
> Word 2003
>
> Trying to create an automated form for my church and am stumped as to how
> to do this. I have a calendar form (actually two of them) that populate
> formfields (StartDate and EndDate). I have another formfield (TotalDays)
> that I cm trying to populate with the number of days difference between
> the other two formfields. I assigned the following macro to the "Entry"
> of the TotalDays field. However, it is not working.
>
> Sub CalculateTotalDays()
> ActiveDocument.FormFields("TotalDays").Result = DateDiff("d", EndDate,
> StartDate)
> End Sub
>
> I am assuming that Word can't recognize formfields the same way Acces does
> to know to use them in the calculation, but I can't seem to find a way to
> make it work.
>
> Any ideas? TIA!
> --
> Bill Foley
> Microsoft PowerPoint MVP
> Microsoft Office Specialist Master Instructor
> www.pttinc.com
>



Re: Using DateDiff in Formfields... by Greg

Greg
Wed Dec 06 09:59:42 CST 2006

Bill,

I won't enter the fray and say which is more correct (I don't know). I
did it with a macro like this:
Sub CalculateTotalDays()
Dim oFF As FormFields
Dim EndDate As Date
Dim StartDate As Date
Set oFF = ActiveDocument.FormFields
EndDate = oFF("EndDate").Result
StartDate = oFF("StartDate").Result
oFF("TotalDays").Result = DateDiff("d", EndDate, StartDate)
End Sub

Bill Foley wrote:
> Thanks, Graham. I'll give it a go. I'll also hang around for the "correct"
> way from Jezebel! HA!
>
> --
> Bill Foley
> Microsoft PowerPoint MVP
> Microsoft Office Specialist Master Instructor
> www.pttinc.com
> "Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message
> news:%230k3LbUGHHA.1240@TK2MSFTNGP03.phx.gbl...
> > If you don't mind Jezebel's unwarranted scorn, you could do this with a
> > Word field assembly as opposed to a form field for the result. The
> > construction is :
> >
> > {={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
> > a{=INT((14-{StartDate \@ M})/12)}}{SET b{={StartDate \@ yyyy}+4800-a}}{SET
> > c{={StartDate \@ M}+12*a-3}}{SET d{StartDate \@
> > d}}{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045}\# ,0}
> >
> > www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902 will give you the
> > source document containing the fields to avoid trying to reconstruct from
> > here. Don't forget to check the calculate on exit check boxes of the two
> > date source fields.
> >
> >
> > --
> > <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> > Graham Mayor - Word MVP
> >
> > My web site www.gmayor.com
> > Word MVP web site http://word.mvps.org
> > <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> >
> >
> >
> > Bill Foley wrote:
> >> Hey Gang,
> >>
> >> Word 2003
> >>
> >> Trying to create an automated form for my church and am stumped as to
> >> how to do this. I have a calendar form (actually two of them) that
> >> populate formfields (StartDate and EndDate). I have another
> >> formfield (TotalDays) that I cm trying to populate with the number of
> >> days difference between the other two formfields. I assigned the
> >> following macro to the "Entry" of the TotalDays field. However, it
> >> is not working.
> >> Sub CalculateTotalDays()
> >> ActiveDocument.FormFields("TotalDays").Result = DateDiff("d",
> >> EndDate, StartDate)
> >> End Sub
> >>
> >> I am assuming that Word can't recognize formfields the same way Acces
> >> does to know to use them in the calculation, but I can't seem to find
> >> a way to make it work.
> >>
> >> Any ideas? TIA!
> >
> >


Re: Using DateDiff in Formfields... by Bill

Bill
Wed Dec 06 10:13:07 CST 2006

Works a peach! THANKS!

--
Bill Foley
Microsoft PowerPoint MVP
Microsoft Office Specialist Master Instructor
www.pttinc.com
"Greg Maxey" <gmaxey@mvps.org> wrote in message
news:1165420782.543525.118270@79g2000cws.googlegroups.com...
> Bill,
>
> I won't enter the fray and say which is more correct (I don't know). I
> did it with a macro like this:
> Sub CalculateTotalDays()
> Dim oFF As FormFields
> Dim EndDate As Date
> Dim StartDate As Date
> Set oFF = ActiveDocument.FormFields
> EndDate = oFF("EndDate").Result
> StartDate = oFF("StartDate").Result
> oFF("TotalDays").Result = DateDiff("d", EndDate, StartDate)
> End Sub
>
> Bill Foley wrote:
>> Thanks, Graham. I'll give it a go. I'll also hang around for the
>> "correct"
>> way from Jezebel! HA!
>>
>> --
>> Bill Foley
>> Microsoft PowerPoint MVP
>> Microsoft Office Specialist Master Instructor
>> www.pttinc.com
>> "Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message
>> news:%230k3LbUGHHA.1240@TK2MSFTNGP03.phx.gbl...
>> > If you don't mind Jezebel's unwarranted scorn, you could do this with a
>> > Word field assembly as opposed to a form field for the result. The
>> > construction is :
>> >
>> > {={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
>> > a{=INT((14-{StartDate \@ M})/12)}}{SET b{={StartDate \@
>> > yyyy}+4800-a}}{SET
>> > c{={StartDate \@ M}+12*a-3}}{SET d{StartDate \@
>> > d}}{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045}\#
>> > ,0}
>> >
>> > www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902 will give you
>> > the
>> > source document containing the fields to avoid trying to reconstruct
>> > from
>> > here. Don't forget to check the calculate on exit check boxes of the
>> > two
>> > date source fields.
>> >
>> >
>> > --
>> > <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> > Graham Mayor - Word MVP
>> >
>> > My web site www.gmayor.com
>> > Word MVP web site http://word.mvps.org
>> > <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> >
>> >
>> >
>> > Bill Foley wrote:
>> >> Hey Gang,
>> >>
>> >> Word 2003
>> >>
>> >> Trying to create an automated form for my church and am stumped as to
>> >> how to do this. I have a calendar form (actually two of them) that
>> >> populate formfields (StartDate and EndDate). I have another
>> >> formfield (TotalDays) that I cm trying to populate with the number of
>> >> days difference between the other two formfields. I assigned the
>> >> following macro to the "Entry" of the TotalDays field. However, it
>> >> is not working.
>> >> Sub CalculateTotalDays()
>> >> ActiveDocument.FormFields("TotalDays").Result = DateDiff("d",
>> >> EndDate, StartDate)
>> >> End Sub
>> >>
>> >> I am assuming that Word can't recognize formfields the same way Acces
>> >> does to know to use them in the calculation, but I can't seem to find
>> >> a way to make it work.
>> >>
>> >> Any ideas? TIA!
>> >
>> >
>



Re: Using DateDiff in Formfields... by Bill

Bill
Wed Dec 06 10:13:22 CST 2006

Kinda what I figured. Got it working now. THANKS!

--
Bill Foley
Microsoft PowerPoint MVP
Microsoft Office Specialist Master Instructor
www.pttinc.com
"Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org> wrote in message
news:%23SGTn8UGHHA.1804@TK2MSFTNGP02.phx.gbl...
> ActiveDocument.FormFields("TotalDays").Result = DateDiff("d", EndDate,
> StartDate)
>
> Should be:
>
> ActiveDocument.FormFields("TotalDays").Result = DateDiff("d",
> ActiveDocument.FormFields("EndDate").Result,
> ActiveDocument.FormFields("StartDate").Result)
>
>
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> "Bill Foley" <pttincatitexasdotnet> wrote in message
> news:%23%23c7rMUGHHA.4688@TK2MSFTNGP04.phx.gbl...
>> Hey Gang,
>>
>> Word 2003
>>
>> Trying to create an automated form for my church and am stumped as to how
>> to do this. I have a calendar form (actually two of them) that populate
>> formfields (StartDate and EndDate). I have another formfield (TotalDays)
>> that I cm trying to populate with the number of days difference between
>> the other two formfields. I assigned the following macro to the "Entry"
>> of the TotalDays field. However, it is not working.
>>
>> Sub CalculateTotalDays()
>> ActiveDocument.FormFields("TotalDays").Result = DateDiff("d", EndDate,
>> StartDate)
>> End Sub
>>
>> I am assuming that Word can't recognize formfields the same way Acces
>> does to know to use them in the calculation, but I can't seem to find a
>> way to make it work.
>>
>> Any ideas? TIA!
>> --
>> Bill Foley
>> Microsoft PowerPoint MVP
>> Microsoft Office Specialist Master Instructor
>> www.pttinc.com
>>
>
>



Re: Using DateDiff in Formfields... by Bill

Bill
Wed Dec 06 10:14:18 CST 2006

Kept getting some sort of "syntax error" so I gave into the other way. Must
not be smart enough to use the "official field" method! HA!

THANKS!

--
Bill Foley
Microsoft PowerPoint MVP
Microsoft Office Specialist Master Instructor
www.pttinc.com
"Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message
news:%230k3LbUGHHA.1240@TK2MSFTNGP03.phx.gbl...
> If you don't mind Jezebel's unwarranted scorn, you could do this with a
> Word field assembly as opposed to a form field for the result. The
> construction is :
>
> {={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
> a{=INT((14-{StartDate \@ M})/12)}}{SET b{={StartDate \@ yyyy}+4800-a}}{SET
> c{={StartDate \@ M}+12*a-3}}{SET d{StartDate \@
> d}}{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045}\# ,0}
>
> www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902 will give you the
> source document containing the fields to avoid trying to reconstruct from
> here. Don't forget to check the calculate on exit check boxes of the two
> date source fields.
>
>
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - Word MVP
>
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
>
>
> Bill Foley wrote:
>> Hey Gang,
>>
>> Word 2003
>>
>> Trying to create an automated form for my church and am stumped as to
>> how to do this. I have a calendar form (actually two of them) that
>> populate formfields (StartDate and EndDate). I have another
>> formfield (TotalDays) that I cm trying to populate with the number of
>> days difference between the other two formfields. I assigned the
>> following macro to the "Entry" of the TotalDays field. However, it
>> is not working.
>> Sub CalculateTotalDays()
>> ActiveDocument.FormFields("TotalDays").Result = DateDiff("d",
>> EndDate, StartDate)
>> End Sub
>>
>> I am assuming that Word can't recognize formfields the same way Acces
>> does to know to use them in the calculation, but I can't seem to find
>> a way to make it work.
>>
>> Any ideas? TIA!
>
>



Re: Using DateDiff in Formfields... by Graham

Graham
Thu Dec 07 00:10:35 CST 2006

Curious - as the default settings in the master document even have the same
field names. It works for me straight out of the box by simply cutting and
pasting the code. the problem may have been that of having the calculate on
exit checkbox checked on both fields as I suggested, rather than on the
second only as there would be no date in the second field when starting and
that would confuse it :)

However our friend Jezebel will no doubt have a wry smile on his face ;)

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

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

Bill Foley wrote:
> Kept getting some sort of "syntax error" so I gave into the other
> way. Must not be smart enough to use the "official field" method! HA!
> THANKS!
>
>> If you don't mind Jezebel's unwarranted scorn, you could do this
>> with a Word field assembly as opposed to a form field for the
>> result. The construction is :
>>
>> {={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
>> a{=INT((14-{StartDate \@ M})/12)}}{SET b{={StartDate \@
>> yyyy}+4800-a}}{SET c{={StartDate \@ M}+12*a-3}}{SET d{StartDate \@
>> d}}{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045}\#
>> ,0} www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902 will give you
>> the source document containing the fields to avoid trying to
>> reconstruct from here. Don't forget to check the calculate on exit
>> check boxes of the two date source fields.
>>
>>
>> --
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> Graham Mayor - Word MVP
>>
>> My web site www.gmayor.com
>> Word MVP web site http://word.mvps.org
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>
>>
>>
>> Bill Foley wrote:
>>> Hey Gang,
>>>
>>> Word 2003
>>>
>>> Trying to create an automated form for my church and am stumped as
>>> to how to do this. I have a calendar form (actually two of them)
>>> that populate formfields (StartDate and EndDate). I have another
>>> formfield (TotalDays) that I cm trying to populate with the number
>>> of days difference between the other two formfields. I assigned the
>>> following macro to the "Entry" of the TotalDays field. However, it
>>> is not working.
>>> Sub CalculateTotalDays()
>>> ActiveDocument.FormFields("TotalDays").Result = DateDiff("d",
>>> EndDate, StartDate)
>>> End Sub
>>>
>>> I am assuming that Word can't recognize formfields the same way
>>> Acces does to know to use them in the calculation, but I can't seem
>>> to find a way to make it work.
>>>
>>> Any ideas? TIA!



Re: Using DateDiff in Formfields... by macropod

macropod
Thu Dec 07 01:34:07 CST 2006

Hi Bill,

If you used the field coding Graham posted, you need to ensure all the field
braces (i.e. '{ }') are created in pairs via Ctrl-F9. Simply typing them
won't work and will produce syntax errors just like you described.

Cheers

--
macropod
[MVP - Microsoft Word]


"Bill Foley" <pttincatitexasdotnet> wrote in message
news:OYX%23OGVGHHA.3616@TK2MSFTNGP02.phx.gbl...
> Kept getting some sort of "syntax error" so I gave into the other way.
Must
> not be smart enough to use the "official field" method! HA!
>
> THANKS!
>
> --
> Bill Foley
> Microsoft PowerPoint MVP
> Microsoft Office Specialist Master Instructor
> www.pttinc.com
> "Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message
> news:%230k3LbUGHHA.1240@TK2MSFTNGP03.phx.gbl...
> > If you don't mind Jezebel's unwarranted scorn, you could do this with a
> > Word field assembly as opposed to a form field for the result. The
> > construction is :
> >
> > {={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
> > a{=INT((14-{StartDate \@ M})/12)}}{SET b{={StartDate \@
yyyy}+4800-a}}{SET
> > c{={StartDate \@ M}+12*a-3}}{SET d{StartDate \@
> > d}}{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045}\#
,0}
> >
> > www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902 will give you the
> > source document containing the fields to avoid trying to reconstruct
from
> > here. Don't forget to check the calculate on exit check boxes of the two
> > date source fields.
> >
> >
> > --
> > <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> > Graham Mayor - Word MVP
> >
> > My web site www.gmayor.com
> > Word MVP web site http://word.mvps.org
> > <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> >
> >
> >
> > Bill Foley wrote:
> >> Hey Gang,
> >>
> >> Word 2003
> >>
> >> Trying to create an automated form for my church and am stumped as to
> >> how to do this. I have a calendar form (actually two of them) that
> >> populate formfields (StartDate and EndDate). I have another
> >> formfield (TotalDays) that I cm trying to populate with the number of
> >> days difference between the other two formfields. I assigned the
> >> following macro to the "Entry" of the TotalDays field. However, it
> >> is not working.
> >> Sub CalculateTotalDays()
> >> ActiveDocument.FormFields("TotalDays").Result = DateDiff("d",
> >> EndDate, StartDate)
> >> End Sub
> >>
> >> I am assuming that Word can't recognize formfields the same way Acces
> >> does to know to use them in the calculation, but I can't seem to find
> >> a way to make it work.
> >>
> >> Any ideas? TIA!
> >
> >
>
>



Re: Using DateDiff in Formfields... by Graham

Graham
Thu Dec 07 04:10:39 CST 2006

I did suggest he pasted the original from your source document which will
work as supplied - even to the correct field names.

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

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

macropod wrote:
> Hi Bill,
>
> If you used the field coding Graham posted, you need to ensure all
> the field braces (i.e. '{ }') are created in pairs via Ctrl-F9.
> Simply typing them won't work and will produce syntax errors just
> like you described.
>
> Cheers
>
>
> "Bill Foley" <pttincatitexasdotnet> wrote in message
> news:OYX%23OGVGHHA.3616@TK2MSFTNGP02.phx.gbl...
>> Kept getting some sort of "syntax error" so I gave into the other
>> way. Must not be smart enough to use the "official field" method!
>> HA!
>>
>> THANKS!
>>
>> --
>> Bill Foley
>> Microsoft PowerPoint MVP
>> Microsoft Office Specialist Master Instructor
>> www.pttinc.com
>> "Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message
>> news:%230k3LbUGHHA.1240@TK2MSFTNGP03.phx.gbl...
>>> If you don't mind Jezebel's unwarranted scorn, you could do this
>>> with a Word field assembly as opposed to a form field for the
>>> result. The construction is :
>>>
>>> {={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
>>> a{=INT((14-{StartDate \@ M})/12)}}{SET b{={StartDate \@
>>> yyyy}+4800-a}}{SET c{={StartDate \@ M}+12*a-3}}{SET d{StartDate \@
>>> d}}{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045}\#
>>> ,0}
>>>
>>> www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902 will give
>>> you the source document containing the fields to avoid trying to
>>> reconstruct from here. Don't forget to check the calculate on exit
>>> check boxes of the two date source fields.
>>>
>>>
>>> --
>>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>> Graham Mayor - Word MVP
>>>
>>> My web site www.gmayor.com
>>> Word MVP web site http://word.mvps.org
>>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>>
>>>
>>>
>>> Bill Foley wrote:
>>>> Hey Gang,
>>>>
>>>> Word 2003
>>>>
>>>> Trying to create an automated form for my church and am stumped as
>>>> to how to do this. I have a calendar form (actually two of them)
>>>> that populate formfields (StartDate and EndDate). I have another
>>>> formfield (TotalDays) that I cm trying to populate with the number
>>>> of days difference between the other two formfields. I assigned
>>>> the following macro to the "Entry" of the TotalDays field.
>>>> However, it is not working.
>>>> Sub CalculateTotalDays()
>>>> ActiveDocument.FormFields("TotalDays").Result = DateDiff("d",
>>>> EndDate, StartDate)
>>>> End Sub
>>>>
>>>> I am assuming that Word can't recognize formfields the same way
>>>> Acces does to know to use them in the calculation, but I can't
>>>> seem to find a way to make it work.
>>>>
>>>> Any ideas? TIA!



Re: Using DateDiff in Formfields... by macropod

macropod
Thu Dec 07 05:43:26 CST 2006

Hi Graham,

Yes, I noticed that. Not doing so and messing up the coding is the only
reason I can think of for the syntax error.

Cheers

--
macropod
[MVP - Microsoft Word]


"Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message
news:OQ3LxfeGHHA.816@TK2MSFTNGP06.phx.gbl...
> I did suggest he pasted the original from your source document which will
> work as supplied - even to the correct field names.
>
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - Word MVP
>
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
> macropod wrote:
> > Hi Bill,
> >
> > If you used the field coding Graham posted, you need to ensure all
> > the field braces (i.e. '{ }') are created in pairs via Ctrl-F9.
> > Simply typing them won't work and will produce syntax errors just
> > like you described.
> >
> > Cheers
> >
> >
> > "Bill Foley" <pttincatitexasdotnet> wrote in message
> > news:OYX%23OGVGHHA.3616@TK2MSFTNGP02.phx.gbl...
> >> Kept getting some sort of "syntax error" so I gave into the other
> >> way. Must not be smart enough to use the "official field" method!
> >> HA!
> >>
> >> THANKS!
> >>
> >> --
> >> Bill Foley
> >> Microsoft PowerPoint MVP
> >> Microsoft Office Specialist Master Instructor
> >> www.pttinc.com
> >> "Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message
> >> news:%230k3LbUGHHA.1240@TK2MSFTNGP03.phx.gbl...
> >>> If you don't mind Jezebel's unwarranted scorn, you could do this
> >>> with a Word field assembly as opposed to a form field for the
> >>> result. The construction is :
> >>>
> >>> {={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
> >>> a{=INT((14-{StartDate \@ M})/12)}}{SET b{={StartDate \@
> >>> yyyy}+4800-a}}{SET c{={StartDate \@ M}+12*a-3}}{SET d{StartDate \@
> >>> d}}{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045}\#
> >>> ,0}
> >>>
> >>> www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902 will give
> >>> you the source document containing the fields to avoid trying to
> >>> reconstruct from here. Don't forget to check the calculate on exit
> >>> check boxes of the two date source fields.
> >>>
> >>>
> >>> --
> >>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> >>> Graham Mayor - Word MVP
> >>>
> >>> My web site www.gmayor.com
> >>> Word MVP web site http://word.mvps.org
> >>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> >>>
> >>>
> >>>
> >>> Bill Foley wrote:
> >>>> Hey Gang,
> >>>>
> >>>> Word 2003
> >>>>
> >>>> Trying to create an automated form for my church and am stumped as
> >>>> to how to do this. I have a calendar form (actually two of them)
> >>>> that populate formfields (StartDate and EndDate). I have another
> >>>> formfield (TotalDays) that I cm trying to populate with the number
> >>>> of days difference between the other two formfields. I assigned
> >>>> the following macro to the "Entry" of the TotalDays field.
> >>>> However, it is not working.
> >>>> Sub CalculateTotalDays()
> >>>> ActiveDocument.FormFields("TotalDays").Result = DateDiff("d",
> >>>> EndDate, StartDate)
> >>>> End Sub
> >>>>
> >>>> I am assuming that Word can't recognize formfields the same way
> >>>> Acces does to know to use them in the calculation, but I can't
> >>>> seem to find a way to make it work.
> >>>>
> >>>> Any ideas? TIA!
>
>