We help IT Professionals succeed at work.

Troubleshooting a field script to calculate a date

sirjulio
sirjulio asked
on
I'm teaching myself how to use the field editing in Microsoft Word 2007 using an example from http://addbalance.com/word/datefields2.htm
I have entered it all in manually adding all the { } using ctrl+f9. At the end I right clicked the field and selected 'update field' and the only value showing based on today's date was: 8,2008

The attached code is pasted from the website, not from what I've entered. I'm having trouble getting the code on the clipboard, I'm going over it again now carefully. I'm putting this question here now in case any expert out there can see a glaring syntax error or comment on common oversights.

Thank you
{ QUOTE "{ SET " Delay" "14"  }
{  SET "DaysInMonth" { IF { CreateDate \@ "MM" } <> 2
{  = ROUND(30.575*{ CreateDate \@ "MM" },0)-
ROUND(30.575*{ = { CreateDate \@ "MM" } -1 },0) }
{  IF {  = MOD( { CreateDate \@"yy" } , 4 ) } > 0 "28" "29" } } }
{ SET "NextMonth" {  IF {  CreateDate \@ "MM" } = 12 "1/97" 
"{ = {  CreateDate \@ "MM" } + 1 }/97 } }
{  IF {   = {  REF "Delay" } + { CreateDate \@ "dd" } } <= { REF"DaysInMonth" }
{ CreateDate \@ "MMMM { = {  REF "Delay" } + { CreateDate \@ "dd" } }, yyyy"}{ QUOTE { NextMonth \@ "MMMM" } 
{ = { REF "Delay" } + { CreateDate \@ "dd" } - { REF"DaysInMonth" } }, 
{ IF { CreateDate \@ "MM" } <> 12 { CreateDate \@ "yyyy" }
{ CreateDate \@ "{ = 1 + { CreateDate \@ "yyyy" } \# "xxxx" }" } } } }" }

Open in new window

Comment
Watch Question

Retired
CERTIFIED EXPERT
Top Expert 2012
Commented:
That particular set of nested fields is the reason that I always recommend using VBA for date arithmetic. In my opinon it is far too difficult to type in for for practical use.

It is certainly not the place to start learnng about fields.

You could try attaching a document with your efforts here. Perhaps someone will have the time to debug it.

Author

Commented:
Thanks Graham that actually sounds like a great idea. I'll close this question here and create a new one in the VBA zone

Explore More ContentExplore courses, solutions, and other research materials related to this topic.