Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.newusers
|
|||
|
|||
Need help with Field Codes
I'm trying to put a field code into my Word 2002 document but having trouble
getting the syntax just right. I want the field code to be replaced by the current year plus 1. Therefore, if the document is being generated today, I want the field code to put 2007 at a specifc place within my document. I know that the field code {DATE \@ "YYYY"} will give me the current year. I'm struggling with how to write the field code that will give me the next year. First of all, I'm not sure whether I can write an expression that adds 1 to year and display that result directly or whether I have to first transform that result to a character string. Second, I'm not sure how to get the result even as an integer. To get an integer result, I'm guessing that I have to use an = formula, something like this: {={DATE \@ "YYYY"}+1} To get a character string result, I'm guessing that I have to imbed all of that in a QUOTE, something like this: {QUOTE "{={DATE \@ "YYYY"} +1}/1 \@ "YYYY"} This last guess was inspired by the Help article on QUOTE. Unfortunately, I inevitably get a Syntax Error whenever I try to use either approach, no matter how carefully I try to write the field code. (I'm a veteran programmer and I know how important it is to get the syntax of a statement just right.) What's worse is that everytime I get the Syntax Error, the original field code is destroyed and I have to painstakingly type it all in again rather than just altering it and trying it again. Can anyone help me out? -- Rhino |
#2
Posted to microsoft.public.word.newusers
|
|||
|
|||
Need help with Field Codes
No need for a QUOTE field. This works just fine for me (Word 2003) with this
syntax: { = { DATE \@ "YYYY" } +1 } Note the spaces. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... I'm trying to put a field code into my Word 2002 document but having trouble getting the syntax just right. I want the field code to be replaced by the current year plus 1. Therefore, if the document is being generated today, I want the field code to put 2007 at a specifc place within my document. I know that the field code {DATE \@ "YYYY"} will give me the current year. I'm struggling with how to write the field code that will give me the next year. First of all, I'm not sure whether I can write an expression that adds 1 to year and display that result directly or whether I have to first transform that result to a character string. Second, I'm not sure how to get the result even as an integer. To get an integer result, I'm guessing that I have to use an = formula, something like this: {={DATE \@ "YYYY"}+1} To get a character string result, I'm guessing that I have to imbed all of that in a QUOTE, something like this: {QUOTE "{={DATE \@ "YYYY"} +1}/1 \@ "YYYY"} This last guess was inspired by the Help article on QUOTE. Unfortunately, I inevitably get a Syntax Error whenever I try to use either approach, no matter how carefully I try to write the field code. (I'm a veteran programmer and I know how important it is to get the syntax of a statement just right.) What's worse is that everytime I get the Syntax Error, the original field code is destroyed and I have to painstakingly type it all in again rather than just altering it and trying it again. Can anyone help me out? -- Rhino |
#3
Posted to microsoft.public.word.newusers
|
|||
|
|||
Need help with Field Codes
There's got to be some kind of a knack that I'm just not getting here.
I tried doing a CTRL-F9 to produce a pair of heavy braces at the right point in my document. That worked. Then, when I pasted the exact string you provided in your note, including the spaces, that seemed to work too. But as soon as I pressed the "Propagate" icon on the Mail Merge toolbar, the spot where I had entered the field code said !Syntax Error, {. VENT I've been messing with this seemingly simple task of inputting a formula for calculating the next year for something like two hours and my head's getting sore from banging it on the wall. I seem to have tried every variation I can imagine of DATE, SET, =, and everything else I could think of and it inevitably gets me a syntax error!! What the heck is going on here?? I've done a Google search on the newsgroup and seen several variations of your suggestion supplied by various responders and none of them seem to have any followup questions, which gives the impression that the original poster had no problem using this formula in their documents. So why do I alone seem to have problems with this?? Is there some kind of document wide setting that has the wrong value or something?? /VENT For what it's worth, I've also tried doing Insert/Field, selecting =, then entering { DATE \@ "YYYY" } +1 in the Formula field, then choosing 0 as the number format. That doesn't work either. I've tried using lowercase "yyyy" instead of "YYYY". That didn't help. Everything leads me back to this Syntax Error. What boneheaded mistake am I making here? -- Rhino "Suzanne S. Barnhill" wrote in message ... No need for a QUOTE field. This works just fine for me (Word 2003) with this syntax: { = { DATE \@ "YYYY" } +1 } Note the spaces. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... I'm trying to put a field code into my Word 2002 document but having trouble getting the syntax just right. I want the field code to be replaced by the current year plus 1. Therefore, if the document is being generated today, I want the field code to put 2007 at a specifc place within my document. I know that the field code {DATE \@ "YYYY"} will give me the current year. I'm struggling with how to write the field code that will give me the next year. First of all, I'm not sure whether I can write an expression that adds 1 to year and display that result directly or whether I have to first transform that result to a character string. Second, I'm not sure how to get the result even as an integer. To get an integer result, I'm guessing that I have to use an = formula, something like this: {={DATE \@ "YYYY"}+1} To get a character string result, I'm guessing that I have to imbed all of that in a QUOTE, something like this: {QUOTE "{={DATE \@ "YYYY"} +1}/1 \@ "YYYY"} This last guess was inspired by the Help article on QUOTE. Unfortunately, I inevitably get a Syntax Error whenever I try to use either approach, no matter how carefully I try to write the field code. (I'm a veteran programmer and I know how important it is to get the syntax of a statement just right.) What's worse is that everytime I get the Syntax Error, the original field code is destroyed and I have to painstakingly type it all in again rather than just altering it and trying it again. Can anyone help me out? -- Rhino |
#4
Posted to microsoft.public.word.newusers
|
|||
|
|||
Need help with Field Codes
You did not mention a mail merge. Date fields are not compatible with mail
merges. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... There's got to be some kind of a knack that I'm just not getting here. I tried doing a CTRL-F9 to produce a pair of heavy braces at the right point in my document. That worked. Then, when I pasted the exact string you provided in your note, including the spaces, that seemed to work too. But as soon as I pressed the "Propagate" icon on the Mail Merge toolbar, the spot where I had entered the field code said !Syntax Error, {. VENT I've been messing with this seemingly simple task of inputting a formula for calculating the next year for something like two hours and my head's getting sore from banging it on the wall. I seem to have tried every variation I can imagine of DATE, SET, =, and everything else I could think of and it inevitably gets me a syntax error!! What the heck is going on here?? I've done a Google search on the newsgroup and seen several variations of your suggestion supplied by various responders and none of them seem to have any followup questions, which gives the impression that the original poster had no problem using this formula in their documents. So why do I alone seem to have problems with this?? Is there some kind of document wide setting that has the wrong value or something?? /VENT For what it's worth, I've also tried doing Insert/Field, selecting =, then entering { DATE \@ "YYYY" } +1 in the Formula field, then choosing 0 as the number format. That doesn't work either. I've tried using lowercase "yyyy" instead of "YYYY". That didn't help. Everything leads me back to this Syntax Error. What boneheaded mistake am I making here? -- Rhino "Suzanne S. Barnhill" wrote in message ... No need for a QUOTE field. This works just fine for me (Word 2003) with this syntax: { = { DATE \@ "YYYY" } +1 } Note the spaces. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... I'm trying to put a field code into my Word 2002 document but having trouble getting the syntax just right. I want the field code to be replaced by the current year plus 1. Therefore, if the document is being generated today, I want the field code to put 2007 at a specifc place within my document. I know that the field code {DATE \@ "YYYY"} will give me the current year. I'm struggling with how to write the field code that will give me the next year. First of all, I'm not sure whether I can write an expression that adds 1 to year and display that result directly or whether I have to first transform that result to a character string. Second, I'm not sure how to get the result even as an integer. To get an integer result, I'm guessing that I have to use an = formula, something like this: {={DATE \@ "YYYY"}+1} To get a character string result, I'm guessing that I have to imbed all of that in a QUOTE, something like this: {QUOTE "{={DATE \@ "YYYY"} +1}/1 \@ "YYYY"} This last guess was inspired by the Help article on QUOTE. Unfortunately, I inevitably get a Syntax Error whenever I try to use either approach, no matter how carefully I try to write the field code. (I'm a veteran programmer and I know how important it is to get the syntax of a statement just right.) What's worse is that everytime I get the Syntax Error, the original field code is destroyed and I have to painstakingly type it all in again rather than just altering it and trying it again. Can anyone help me out? -- Rhino |
#5
Posted to microsoft.public.word.newusers
|
|||
|
|||
Need help with Field Codes
So you're saying that there's no way to put the current year plus 1
(whatever the current year is when I run the mail merge) in each label of a set of labels? No way at all?? Are you sure? I find that surprising: Word seems pretty powerful and the task of putting a date on each label seems pretty trivial. By the way, I can put the current date on a label easily enough, it's just the result of adding 1 to the current year that is giving me trouble. Considering that you can calculate quantities like the current year plus 1 in other places within the document, why not do the same in a mail merge? By the way, I was able to get past the Syntax Error problem I reported earlier. I now have perfectly valid looking code that doesn't give me an error message: { DATE = {={DATE \@ yyyy} + 1}} However, although the expression seems to be calculating the current year plus 1, the result of the calculation always seems to be the current year NOT the current year plus 1. For what it's worth, I have tried umpteen variations of this formula, some of which used CREATEDATE instead of DATE and some of which used "yyyy" instead of yyyy, but I always get the current year, not current year plus 1. I've tried adding numbers much greater than 1 - on the theory that 1 might have been interpreted as 1 millisecond instead of 1 year in this expression - but even with huge numbers like 99999999999999999, the result of the addition is always the current year. -- Rhino "Suzanne S. Barnhill" wrote in message ... You did not mention a mail merge. Date fields are not compatible with mail merges. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... There's got to be some kind of a knack that I'm just not getting here. I tried doing a CTRL-F9 to produce a pair of heavy braces at the right point in my document. That worked. Then, when I pasted the exact string you provided in your note, including the spaces, that seemed to work too. But as soon as I pressed the "Propagate" icon on the Mail Merge toolbar, the spot where I had entered the field code said !Syntax Error, {. VENT I've been messing with this seemingly simple task of inputting a formula for calculating the next year for something like two hours and my head's getting sore from banging it on the wall. I seem to have tried every variation I can imagine of DATE, SET, =, and everything else I could think of and it inevitably gets me a syntax error!! What the heck is going on here?? I've done a Google search on the newsgroup and seen several variations of your suggestion supplied by various responders and none of them seem to have any followup questions, which gives the impression that the original poster had no problem using this formula in their documents. So why do I alone seem to have problems with this?? Is there some kind of document wide setting that has the wrong value or something?? /VENT For what it's worth, I've also tried doing Insert/Field, selecting =, then entering { DATE \@ "YYYY" } +1 in the Formula field, then choosing 0 as the number format. That doesn't work either. I've tried using lowercase "yyyy" instead of "YYYY". That didn't help. Everything leads me back to this Syntax Error. What boneheaded mistake am I making here? -- Rhino "Suzanne S. Barnhill" wrote in message ... No need for a QUOTE field. This works just fine for me (Word 2003) with this syntax: { = { DATE \@ "YYYY" } +1 } Note the spaces. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... I'm trying to put a field code into my Word 2002 document but having trouble getting the syntax just right. I want the field code to be replaced by the current year plus 1. Therefore, if the document is being generated today, I want the field code to put 2007 at a specifc place within my document. I know that the field code {DATE \@ "YYYY"} will give me the current year. I'm struggling with how to write the field code that will give me the next year. First of all, I'm not sure whether I can write an expression that adds 1 to year and display that result directly or whether I have to first transform that result to a character string. Second, I'm not sure how to get the result even as an integer. To get an integer result, I'm guessing that I have to use an = formula, something like this: {={DATE \@ "YYYY"}+1} To get a character string result, I'm guessing that I have to imbed all of that in a QUOTE, something like this: {QUOTE "{={DATE \@ "YYYY"} +1}/1 \@ "YYYY"} This last guess was inspired by the Help article on QUOTE. Unfortunately, I inevitably get a Syntax Error whenever I try to use either approach, no matter how carefully I try to write the field code. (I'm a veteran programmer and I know how important it is to get the syntax of a statement just right.) What's worse is that everytime I get the Syntax Error, the original field code is destroyed and I have to painstakingly type it all in again rather than just altering it and trying it again. Can anyone help me out? -- Rhino |
#6
Posted to microsoft.public.word.newusers
|
|||
|
|||
Need help with Field Codes
I get the current year plus 1 with the field I suggested--no problems. If
the date field is updated and correct in your mail merge main document before you merge the labels, then it should probably be okay on the labels. What I was (incorrectly) remembering is that a CREATEDATE field in the header of a mail merge main document is converted to plain text (rather than a CREATEDATE field) in the merged document, and so the date is always the same in the resulting document. But if you use a DATE field (as you are doing) and update it in the mail merge main document before merging, it should work fine. Interestingly, when I tried this the field was preserved in the merged document; I don't know whether this is because it's a DATE field rather than a CREATEDATE field or because it's a formula field. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... So you're saying that there's no way to put the current year plus 1 (whatever the current year is when I run the mail merge) in each label of a set of labels? No way at all?? Are you sure? I find that surprising: Word seems pretty powerful and the task of putting a date on each label seems pretty trivial. By the way, I can put the current date on a label easily enough, it's just the result of adding 1 to the current year that is giving me trouble. Considering that you can calculate quantities like the current year plus 1 in other places within the document, why not do the same in a mail merge? By the way, I was able to get past the Syntax Error problem I reported earlier. I now have perfectly valid looking code that doesn't give me an error message: { DATE = {={DATE \@ yyyy} + 1}} However, although the expression seems to be calculating the current year plus 1, the result of the calculation always seems to be the current year NOT the current year plus 1. For what it's worth, I have tried umpteen variations of this formula, some of which used CREATEDATE instead of DATE and some of which used "yyyy" instead of yyyy, but I always get the current year, not current year plus 1. I've tried adding numbers much greater than 1 - on the theory that 1 might have been interpreted as 1 millisecond instead of 1 year in this expression - but even with huge numbers like 99999999999999999, the result of the addition is always the current year. -- Rhino "Suzanne S. Barnhill" wrote in message ... You did not mention a mail merge. Date fields are not compatible with merges. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... There's got to be some kind of a knack that I'm just not getting here. I tried doing a CTRL-F9 to produce a pair of heavy braces at the right point in my document. That worked. Then, when I pasted the exact string you provided in your note, including the spaces, that seemed to work too. But as soon as I pressed the "Propagate" icon on the Mail Merge toolbar, the spot where I had entered the field code said !Syntax Error, {. VENT I've been messing with this seemingly simple task of inputting a formula for calculating the next year for something like two hours and my head's getting sore from banging it on the wall. I seem to have tried every variation I can imagine of DATE, SET, =, and everything else I could think of and it inevitably gets me a syntax error!! What the heck is going on here?? I've done a Google search on the newsgroup and seen several variations of your suggestion supplied by various responders and none of them seem to have any followup questions, which gives the impression that the original poster had no problem using this formula in their documents. So why do I alone seem to have problems with this?? Is there some kind of document wide setting that has the wrong value or something?? /VENT For what it's worth, I've also tried doing Insert/Field, selecting =, then entering { DATE \@ "YYYY" } +1 in the Formula field, then choosing 0 as the number format. That doesn't work either. I've tried using lowercase "yyyy" instead of "YYYY". That didn't help. Everything leads me back to this Syntax Error. What boneheaded mistake am I making here? -- Rhino "Suzanne S. Barnhill" wrote in message ... No need for a QUOTE field. This works just fine for me (Word 2003) with this syntax: { = { DATE \@ "YYYY" } +1 } Note the spaces. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... I'm trying to put a field code into my Word 2002 document but having trouble getting the syntax just right. I want the field code to be replaced by the current year plus 1. Therefore, if the document is being generated today, I want the field code to put 2007 at a specifc place within my document. I know that the field code {DATE \@ "YYYY"} will give me the current year. I'm struggling with how to write the field code that will give me the next year. First of all, I'm not sure whether I can write an expression that adds 1 to year and display that result directly or whether I have to first transform that result to a character string. Second, I'm not sure how to get the result even as an integer. To get an integer result, I'm guessing that I have to use an = formula, something like this: {={DATE \@ "YYYY"}+1} To get a character string result, I'm guessing that I have to imbed all of that in a QUOTE, something like this: {QUOTE "{={DATE \@ "YYYY"} +1}/1 \@ "YYYY"} This last guess was inspired by the Help article on QUOTE. Unfortunately, I inevitably get a Syntax Error whenever I try to use either approach, no matter how carefully I try to write the field code. (I'm a veteran programmer and I know how important it is to get the syntax of a statement just right.) What's worse is that everytime I get the Syntax Error, the original field code is destroyed and I have to painstakingly type it all in again rather than just altering it and trying it again. Can anyone help me out? -- Rhino |
#7
Posted to microsoft.public.word.newusers
|
|||
|
|||
Need help with Field Codes
I'm not sure what Suzanne is thinking of here, but date and calculation
fields do work in mail merge. You need CTRL+F9 for *each pair* of curly brackets and you need to end up with the following { ={ DATE \@ "yyyy" } +1 } which currently will give you 2007. Press F9 to update the field. For more complex date calculations, see http://www.gmayor.com/insert_a_date_...than_today.htm and for formatting, see http://www.gmayor.com/formatting_word_fields.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Rhino wrote: So you're saying that there's no way to put the current year plus 1 (whatever the current year is when I run the mail merge) in each label of a set of labels? No way at all?? Are you sure? I find that surprising: Word seems pretty powerful and the task of putting a date on each label seems pretty trivial. By the way, I can put the current date on a label easily enough, it's just the result of adding 1 to the current year that is giving me trouble. Considering that you can calculate quantities like the current year plus 1 in other places within the document, why not do the same in a mail merge? By the way, I was able to get past the Syntax Error problem I reported earlier. I now have perfectly valid looking code that doesn't give me an error message: { DATE = {={DATE \@ yyyy} + 1}} However, although the expression seems to be calculating the current year plus 1, the result of the calculation always seems to be the current year NOT the current year plus 1. For what it's worth, I have tried umpteen variations of this formula, some of which used CREATEDATE instead of DATE and some of which used "yyyy" instead of yyyy, but I always get the current year, not current year plus 1. I've tried adding numbers much greater than 1 - on the theory that 1 might have been interpreted as 1 millisecond instead of 1 year in this expression - but even with huge numbers like 99999999999999999, the result of the addition is always the current year. "Suzanne S. Barnhill" wrote in message ... You did not mention a mail merge. Date fields are not compatible with mail merges. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... There's got to be some kind of a knack that I'm just not getting here. I tried doing a CTRL-F9 to produce a pair of heavy braces at the right point in my document. That worked. Then, when I pasted the exact string you provided in your note, including the spaces, that seemed to work too. But as soon as I pressed the "Propagate" icon on the Mail Merge toolbar, the spot where I had entered the field code said !Syntax Error, {. VENT I've been messing with this seemingly simple task of inputting a formula for calculating the next year for something like two hours and my head's getting sore from banging it on the wall. I seem to have tried every variation I can imagine of DATE, SET, =, and everything else I could think of and it inevitably gets me a syntax error!! What the heck is going on here?? I've done a Google search on the newsgroup and seen several variations of your suggestion supplied by various responders and none of them seem to have any followup questions, which gives the impression that the original poster had no problem using this formula in their documents. So why do I alone seem to have problems with this?? Is there some kind of document wide setting that has the wrong value or something?? /VENT For what it's worth, I've also tried doing Insert/Field, selecting =, then entering { DATE \@ "YYYY" } +1 in the Formula field, then choosing 0 as the number format. That doesn't work either. I've tried using lowercase "yyyy" instead of "YYYY". That didn't help. Everything leads me back to this Syntax Error. What boneheaded mistake am I making here? -- Rhino "Suzanne S. Barnhill" wrote in message ... No need for a QUOTE field. This works just fine for me (Word 2003) with this syntax: { = { DATE \@ "YYYY" } +1 } Note the spaces. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... I'm trying to put a field code into my Word 2002 document but having trouble getting the syntax just right. I want the field code to be replaced by the current year plus 1. Therefore, if the document is being generated today, I want the field code to put 2007 at a specifc place within my document. I know that the field code {DATE \@ "YYYY"} will give me the current year. I'm struggling with how to write the field code that will give me the next year. First of all, I'm not sure whether I can write an expression that adds 1 to year and display that result directly or whether I have to first transform that result to a character string. Second, I'm not sure how to get the result even as an integer. To get an integer result, I'm guessing that I have to use an = formula, something like this: {={DATE \@ "YYYY"}+1} To get a character string result, I'm guessing that I have to imbed all of that in a QUOTE, something like this: {QUOTE "{={DATE \@ "YYYY"} +1}/1 \@ "YYYY"} This last guess was inspired by the Help article on QUOTE. Unfortunately, I inevitably get a Syntax Error whenever I try to use either approach, no matter how carefully I try to write the field code. (I'm a veteran programmer and I know how important it is to get the syntax of a statement just right.) What's worse is that everytime I get the Syntax Error, the original field code is destroyed and I have to painstakingly type it all in again rather than just altering it and trying it again. Can anyone help me out? -- Rhino |
#8
Posted to microsoft.public.word.newusers
|
|||
|
|||
Need help with Field Codes
"Graham Mayor" wrote in message ... I'm not sure what Suzanne is thinking of here, but date and calculation fields do work in mail merge. You need CTRL+F9 for *each pair* of curly brackets and you need to end up with the following { ={ DATE \@ "yyyy" } +1 } which currently will give you 2007. Press F9 to update the field. Okay, now I'm officially baffled. :-) I tried your suggestion just now and it worked perfectly. I even tried changing the date on my computer, closed and reopened the document and found that the current year and the current year plus 1 were exactly as I wanted them to be. The reason I'm baffled is that I tried the same formula - and umpteen variations - yesterday and none of them worked correctly: they either gave me an error of some kind or they inevitably showed the current year, not the current year plus 1. I was getting REALLY frustrated by that experience and now everything works just as cleanly and simply as I had expected when I started playing with this formula. I'm completely at a loss to understand why none of this was working yesterday despite several hours of experimentation and now works perfectly today. Do you or Suzanne have any idea what the problem might have been yesterday? I have to believe that there is a rational explanation for this so I find myself wondering what it is. My guess is that the technique I used for entering the formula was flawed in some way. I tried entering the formula in several different ways yesterday: 1. I cut and pasted the formula, except for the outermost braces, directly into my document, specifically in the top left hand label. Then I selected the formula and hit CTRL-F9. 2. I positioned the insert point at the appropriate spot in the document, hit CTRL-F9, typed the = sign, hit CTRL-F9 again, typed the DATE \@ "yyyy" portion of the formula, moved my cursor past the inner closing brace, then typed +1 between the two closing braces. 3. I positioned the insert point at the appropriate spot in the document, clicked Insert/Field, selected = Formula, entered {DATE \@ "yyyy"}+1 in the formula field, clicked OK. Should all of these techniques work in Word 2002? Today, I used the second approach and it worked perfectly, as I said. But I'm sure I did the same thing, probably several times, yesterday and it did NOT work then. For more complex date calculations, see http://www.gmayor.com/insert_a_date_...than_today.htm and for formatting, see http://www.gmayor.com/formatting_word_fields.htm I had a look at your links and found that the first one refers to the Macropod article on advanced date handling. I found that yesterday via Google newsgroups and downloaded his demonstration document. I was using it to compute the next year but his formulas weren't working for me either, despite typing them meticulously. Now that I appear to be out of the Twilight Zone, I may give those another try, just to verify that they work as Macropod describes. The formallting article was also interesting and I may use some of those techniques in future documents, just as I used another of your articles to learn how to do mail merges earlier in the week. You've done a great job with your website! Thank you for taking the time to share your knowledge with those of us who are new to Word and still struggling a bit with some aspects of the product! -- Rhino Rhino wrote: So you're saying that there's no way to put the current year plus 1 (whatever the current year is when I run the mail merge) in each label of a set of labels? No way at all?? Are you sure? I find that surprising: Word seems pretty powerful and the task of putting a date on each label seems pretty trivial. By the way, I can put the current date on a label easily enough, it's just the result of adding 1 to the current year that is giving me trouble. Considering that you can calculate quantities like the current year plus 1 in other places within the document, why not do the same in a mail merge? By the way, I was able to get past the Syntax Error problem I reported earlier. I now have perfectly valid looking code that doesn't give me an error message: { DATE = {={DATE \@ yyyy} + 1}} However, although the expression seems to be calculating the current year plus 1, the result of the calculation always seems to be the current year NOT the current year plus 1. For what it's worth, I have tried umpteen variations of this formula, some of which used CREATEDATE instead of DATE and some of which used "yyyy" instead of yyyy, but I always get the current year, not current year plus 1. I've tried adding numbers much greater than 1 - on the theory that 1 might have been interpreted as 1 millisecond instead of 1 year in this expression - but even with huge numbers like 99999999999999999, the result of the addition is always the current year. "Suzanne S. Barnhill" wrote in message ... You did not mention a mail merge. Date fields are not compatible with mail merges. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... There's got to be some kind of a knack that I'm just not getting here. I tried doing a CTRL-F9 to produce a pair of heavy braces at the right point in my document. That worked. Then, when I pasted the exact string you provided in your note, including the spaces, that seemed to work too. But as soon as I pressed the "Propagate" icon on the Mail Merge toolbar, the spot where I had entered the field code said !Syntax Error, {. VENT I've been messing with this seemingly simple task of inputting a formula for calculating the next year for something like two hours and my head's getting sore from banging it on the wall. I seem to have tried every variation I can imagine of DATE, SET, =, and everything else I could think of and it inevitably gets me a syntax error!! What the heck is going on here?? I've done a Google search on the newsgroup and seen several variations of your suggestion supplied by various responders and none of them seem to have any followup questions, which gives the impression that the original poster had no problem using this formula in their documents. So why do I alone seem to have problems with this?? Is there some kind of document wide setting that has the wrong value or something?? /VENT For what it's worth, I've also tried doing Insert/Field, selecting =, then entering { DATE \@ "YYYY" } +1 in the Formula field, then choosing 0 as the number format. That doesn't work either. I've tried using lowercase "yyyy" instead of "YYYY". That didn't help. Everything leads me back to this Syntax Error. What boneheaded mistake am I making here? -- Rhino "Suzanne S. Barnhill" wrote in message ... No need for a QUOTE field. This works just fine for me (Word 2003) with this syntax: { = { DATE \@ "YYYY" } +1 } Note the spaces. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... I'm trying to put a field code into my Word 2002 document but having trouble getting the syntax just right. I want the field code to be replaced by the current year plus 1. Therefore, if the document is being generated today, I want the field code to put 2007 at a specifc place within my document. I know that the field code {DATE \@ "YYYY"} will give me the current year. I'm struggling with how to write the field code that will give me the next year. First of all, I'm not sure whether I can write an expression that adds 1 to year and display that result directly or whether I have to first transform that result to a character string. Second, I'm not sure how to get the result even as an integer. To get an integer result, I'm guessing that I have to use an = formula, something like this: {={DATE \@ "YYYY"}+1} To get a character string result, I'm guessing that I have to imbed all of that in a QUOTE, something like this: {QUOTE "{={DATE \@ "YYYY"} +1}/1 \@ "YYYY"} This last guess was inspired by the Help article on QUOTE. Unfortunately, I inevitably get a Syntax Error whenever I try to use either approach, no matter how carefully I try to write the field code. (I'm a veteran programmer and I know how important it is to get the syntax of a statement just right.) What's worse is that everytime I get the Syntax Error, the original field code is destroyed and I have to painstakingly type it all in again rather than just altering it and trying it again. Can anyone help me out? -- Rhino |
#9
Posted to microsoft.public.word.newusers
|
|||
|
|||
Need help with Field Codes
You probably didn't update the field after making changes.
Don't even think of typing Macropod's fields. Download the document that contains them and copy the code to your document, then edit it to do what you want. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Rhino wrote: "Graham Mayor" wrote in message ... I'm not sure what Suzanne is thinking of here, but date and calculation fields do work in mail merge. You need CTRL+F9 for *each pair* of curly brackets and you need to end up with the following { ={ DATE \@ "yyyy" } +1 } which currently will give you 2007. Press F9 to update the field. Okay, now I'm officially baffled. :-) I tried your suggestion just now and it worked perfectly. I even tried changing the date on my computer, closed and reopened the document and found that the current year and the current year plus 1 were exactly as I wanted them to be. The reason I'm baffled is that I tried the same formula - and umpteen variations - yesterday and none of them worked correctly: they either gave me an error of some kind or they inevitably showed the current year, not the current year plus 1. I was getting REALLY frustrated by that experience and now everything works just as cleanly and simply as I had expected when I started playing with this formula. I'm completely at a loss to understand why none of this was working yesterday despite several hours of experimentation and now works perfectly today. Do you or Suzanne have any idea what the problem might have been yesterday? I have to believe that there is a rational explanation for this so I find myself wondering what it is. My guess is that the technique I used for entering the formula was flawed in some way. I tried entering the formula in several different ways yesterday: 1. I cut and pasted the formula, except for the outermost braces, directly into my document, specifically in the top left hand label. Then I selected the formula and hit CTRL-F9. 2. I positioned the insert point at the appropriate spot in the document, hit CTRL-F9, typed the = sign, hit CTRL-F9 again, typed the DATE \@ "yyyy" portion of the formula, moved my cursor past the inner closing brace, then typed +1 between the two closing braces. 3. I positioned the insert point at the appropriate spot in the document, clicked Insert/Field, selected = Formula, entered {DATE \@ "yyyy"}+1 in the formula field, clicked OK. Should all of these techniques work in Word 2002? Today, I used the second approach and it worked perfectly, as I said. But I'm sure I did the same thing, probably several times, yesterday and it did NOT work then. For more complex date calculations, see http://www.gmayor.com/insert_a_date_...than_today.htm and for formatting, see http://www.gmayor.com/formatting_word_fields.htm I had a look at your links and found that the first one refers to the Macropod article on advanced date handling. I found that yesterday via Google newsgroups and downloaded his demonstration document. I was using it to compute the next year but his formulas weren't working for me either, despite typing them meticulously. Now that I appear to be out of the Twilight Zone, I may give those another try, just to verify that they work as Macropod describes. The formallting article was also interesting and I may use some of those techniques in future documents, just as I used another of your articles to learn how to do mail merges earlier in the week. You've done a great job with your website! Thank you for taking the time to share your knowledge with those of us who are new to Word and still struggling a bit with some aspects of the product! Rhino wrote: So you're saying that there's no way to put the current year plus 1 (whatever the current year is when I run the mail merge) in each label of a set of labels? No way at all?? Are you sure? I find that surprising: Word seems pretty powerful and the task of putting a date on each label seems pretty trivial. By the way, I can put the current date on a label easily enough, it's just the result of adding 1 to the current year that is giving me trouble. Considering that you can calculate quantities like the current year plus 1 in other places within the document, why not do the same in a mail merge? By the way, I was able to get past the Syntax Error problem I reported earlier. I now have perfectly valid looking code that doesn't give me an error message: { DATE = {={DATE \@ yyyy} + 1}} However, although the expression seems to be calculating the current year plus 1, the result of the calculation always seems to be the current year NOT the current year plus 1. For what it's worth, I have tried umpteen variations of this formula, some of which used CREATEDATE instead of DATE and some of which used "yyyy" instead of yyyy, but I always get the current year, not current year plus 1. I've tried adding numbers much greater than 1 - on the theory that 1 might have been interpreted as 1 millisecond instead of 1 year in this expression - but even with huge numbers like 99999999999999999, the result of the addition is always the current year. "Suzanne S. Barnhill" wrote in message ... You did not mention a mail merge. Date fields are not compatible with mail merges. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... There's got to be some kind of a knack that I'm just not getting here. I tried doing a CTRL-F9 to produce a pair of heavy braces at the right point in my document. That worked. Then, when I pasted the exact string you provided in your note, including the spaces, that seemed to work too. But as soon as I pressed the "Propagate" icon on the Mail Merge toolbar, the spot where I had entered the field code said !Syntax Error, {. VENT I've been messing with this seemingly simple task of inputting a formula for calculating the next year for something like two hours and my head's getting sore from banging it on the wall. I seem to have tried every variation I can imagine of DATE, SET, =, and everything else I could think of and it inevitably gets me a syntax error!! What the heck is going on here?? I've done a Google search on the newsgroup and seen several variations of your suggestion supplied by various responders and none of them seem to have any followup questions, which gives the impression that the original poster had no problem using this formula in their documents. So why do I alone seem to have problems with this?? Is there some kind of document wide setting that has the wrong value or something?? /VENT For what it's worth, I've also tried doing Insert/Field, selecting =, then entering { DATE \@ "YYYY" } +1 in the Formula field, then choosing 0 as the number format. That doesn't work either. I've tried using lowercase "yyyy" instead of "YYYY". That didn't help. Everything leads me back to this Syntax Error. What boneheaded mistake am I making here? -- Rhino "Suzanne S. Barnhill" wrote in message ... No need for a QUOTE field. This works just fine for me (Word 2003) with this syntax: { = { DATE \@ "YYYY" } +1 } Note the spaces. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... I'm trying to put a field code into my Word 2002 document but having trouble getting the syntax just right. I want the field code to be replaced by the current year plus 1. Therefore, if the document is being generated today, I want the field code to put 2007 at a specifc place within my document. I know that the field code {DATE \@ "YYYY"} will give me the current year. I'm struggling with how to write the field code that will give me the next year. First of all, I'm not sure whether I can write an expression that adds 1 to year and display that result directly or whether I have to first transform that result to a character string. Second, I'm not sure how to get the result even as an integer. To get an integer result, I'm guessing that I have to use an = formula, something like this: {={DATE \@ "YYYY"}+1} To get a character string result, I'm guessing that I have to imbed all of that in a QUOTE, something like this: {QUOTE "{={DATE \@ "YYYY"} +1}/1 \@ "YYYY"} This last guess was inspired by the Help article on QUOTE. Unfortunately, I inevitably get a Syntax Error whenever I try to use either approach, no matter how carefully I try to write the field code. (I'm a veteran programmer and I know how important it is to get the syntax of a statement just right.) What's worse is that everytime I get the Syntax Error, the original field code is destroyed and I have to painstakingly type it all in again rather than just altering it and trying it again. Can anyone help me out? -- Rhino |
#10
Posted to microsoft.public.word.newusers
|
|||
|
|||
Need help with Field Codes
I've already backed off somewhat, but do try a CreateDate field, Graham,
before you assert that "date" fields work in mail merges. If you can find a way to get that to work, I'd be grateful. Here's what I get: 1. CreateDate in mail merge main document shows creation date of said document. 2. Merged document shows CreateDate of mail merge main document as plain text (not a field). If I use a Date field instead, then the field is preserved in the merged output, but that's not what I want, though it's a step forward, since it's easier to Ctrl+Shift+F9 to unlink the field than to type the date in manually. The document in question is a list of phone numbers for the members of my Rotary club; I create a new list whenever the membership changes, so I want it to show the revision date. I guess maybe the SaveDate is what I need to shoot for (now that I know there is a possibility of getting some kind of date field to work). -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Graham Mayor" wrote in message ... I'm not sure what Suzanne is thinking of here, but date and calculation fields do work in mail merge. You need CTRL+F9 for *each pair* of curly brackets and you need to end up with the following { ={ DATE \@ "yyyy" } +1 } which currently will give you 2007. Press F9 to update the field. For more complex date calculations, see http://www.gmayor.com/insert_a_date_...than_today.htm and for formatting, see http://www.gmayor.com/formatting_word_fields.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Rhino wrote: So you're saying that there's no way to put the current year plus 1 (whatever the current year is when I run the mail merge) in each label of a set of labels? No way at all?? Are you sure? I find that surprising: Word seems pretty powerful and the task of putting a date on each label seems pretty trivial. By the way, I can put the current date on a label easily enough, it's just the result of adding 1 to the current year that is giving me trouble. Considering that you can calculate quantities like the current year plus 1 in other places within the document, why not do the same in a mail merge? By the way, I was able to get past the Syntax Error problem I reported earlier. I now have perfectly valid looking code that doesn't give me an error message: { DATE = {={DATE \@ yyyy} + 1}} However, although the expression seems to be calculating the current year plus 1, the result of the calculation always seems to be the current year NOT the current year plus 1. For what it's worth, I have tried umpteen variations of this formula, some of which used CREATEDATE instead of DATE and some of which used "yyyy" instead of yyyy, but I always get the current year, not current year plus 1. I've tried adding numbers much greater than 1 - on the theory that 1 might have been interpreted as 1 millisecond instead of 1 year in this expression - but even with huge numbers like 99999999999999999, the result of the addition is always the current year. "Suzanne S. Barnhill" wrote in message ... You did not mention a mail merge. Date fields are not compatible with mail merges. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... There's got to be some kind of a knack that I'm just not getting here. I tried doing a CTRL-F9 to produce a pair of heavy braces at the right point in my document. That worked. Then, when I pasted the exact string you provided in your note, including the spaces, that seemed to work too. But as soon as I pressed the "Propagate" icon on the Mail Merge toolbar, the spot where I had entered the field code said !Syntax Error, {. VENT I've been messing with this seemingly simple task of inputting a formula for calculating the next year for something like two hours and my head's getting sore from banging it on the wall. I seem to have tried every variation I can imagine of DATE, SET, =, and everything else I could think of and it inevitably gets me a syntax error!! What the heck is going on here?? I've done a Google search on the newsgroup and seen several variations of your suggestion supplied by various responders and none of them seem to have any followup questions, which gives the impression that the original poster had no problem using this formula in their documents. So why do I alone seem to have problems with this?? Is there some kind of document wide setting that has the wrong value or something?? /VENT For what it's worth, I've also tried doing Insert/Field, selecting =, then entering { DATE \@ "YYYY" } +1 in the Formula field, then choosing 0 as the number format. That doesn't work either. I've tried using lowercase "yyyy" instead of "YYYY". That didn't help. Everything leads me back to this Syntax Error. What boneheaded mistake am I making here? -- Rhino "Suzanne S. Barnhill" wrote in message ... No need for a QUOTE field. This works just fine for me (Word 2003) with this syntax: { = { DATE \@ "YYYY" } +1 } Note the spaces. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... I'm trying to put a field code into my Word 2002 document but having trouble getting the syntax just right. I want the field code to be replaced by the current year plus 1. Therefore, if the document is being generated today, I want the field code to put 2007 at a specifc place within my document. I know that the field code {DATE \@ "YYYY"} will give me the current year. I'm struggling with how to write the field code that will give me the next year. First of all, I'm not sure whether I can write an expression that adds 1 to year and display that result directly or whether I have to first transform that result to a character string. Second, I'm not sure how to get the result even as an integer. To get an integer result, I'm guessing that I have to use an = formula, something like this: {={DATE \@ "YYYY"}+1} To get a character string result, I'm guessing that I have to imbed all of that in a QUOTE, something like this: {QUOTE "{={DATE \@ "YYYY"} +1}/1 \@ "YYYY"} This last guess was inspired by the Help article on QUOTE. Unfortunately, I inevitably get a Syntax Error whenever I try to use either approach, no matter how carefully I try to write the field code. (I'm a veteran programmer and I know how important it is to get the syntax of a statement just right.) What's worse is that everytime I get the Syntax Error, the original field code is destroyed and I have to painstakingly type it all in again rather than just altering it and trying it again. Can anyone help me out? -- Rhino |
#11
Posted to microsoft.public.word.newusers
|
|||
|
|||
Need help with Field Codes
Rhino wrote:
Okay, now I'm officially baffled. :-) .... I tried your suggestion just now and it worked perfectly. .... The reason I'm baffled is that I tried the same formula - and umpteen variations - yesterday and none of them worked correctly .... I'm completely at a loss to understand why none of this was working yesterday despite several hours of experimentation and now works perfectly today. My 2 cents worth: Apologies everyone for snipping this; the thread was becoming unmanageable, and my comments do not really require the whole context. This problem of something working now that didn't work yesterday 'despite being keyed in exactly the same' is common. IMHO, you did not key it in exactly the same. You probably made some subtle (or even outrageous) mistake and read over it because we all see what we expect to see. I've had the same experience countless times. My mosdt common one was back in the DOS/Quickbasic programming days, when I got continual errors which semed to go back each time to the darned machine (it's always the machine - never the user) not recognising the perfectly valid STRINGS keyword. When I came back to the problem the next day, I would invariable immediately spot that it should be STRING$. So when faced with something that doen't work, I often come back with a fresh mind the next morning, have few glasses of wine, and solve it immediately! (Only kidding about the few glasses of wine; that was last night...) |
#12
Posted to microsoft.public.word.newusers
|
|||
|
|||
Need help with Field Codes
I'm not really sure where you are going with this. The only way that it
would matter if CREATEDATE was converted to plain text during the merge (which it is) would be if you wanted to reprint the merged document at a later date - when it is just as simple to remerge. Take the following example: from the merge document { CREATEDATE \@ "d MMM yyyy" } ... { ={ CREATEDATE \@ "yyyy"} + 1 } { DATE \@ "d MMM yyyy" } ... { ={ DATE \@ "yyyy" } + 1 } { MERGEFIELD MergeDate \@ "d MMM yyyy" } ... { ={ MERGEFIELD MergeDate \@ "yyyy" } +1 } In the merged document 18 Jun 2006 ... { =2006 + 1 } { DATE \@ "d MMM yyyy" } ... { ={ DATE \@ "yyyy" } + 1 } 30 Jun 2006 ... { =2006 +1 } Which prints as 18 Jun 2006 ... 2007 18 Jun 2006 ... 2007 30 Jun 2006 ... 2007 Re-reading your post, it seems to be that Createdate will do what you want. It produces the date that the *merged* document was created and doesn't update so there's no need for you to unlink it? Or have I missed something along the way? I never merge directly to the printer. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Suzanne S. Barnhill wrote: I've already backed off somewhat, but do try a CreateDate field, Graham, before you assert that "date" fields work in mail merges. If you can find a way to get that to work, I'd be grateful. Here's what I get: 1. CreateDate in mail merge main document shows creation date of said document. 2. Merged document shows CreateDate of mail merge main document as plain text (not a field). If I use a Date field instead, then the field is preserved in the merged output, but that's not what I want, though it's a step forward, since it's easier to Ctrl+Shift+F9 to unlink the field than to type the date in manually. The document in question is a list of phone numbers for the members of my Rotary club; I create a new list whenever the membership changes, so I want it to show the revision date. I guess maybe the SaveDate is what I need to shoot for (now that I know there is a possibility of getting some kind of date field to work). "Graham Mayor" wrote in message ... I'm not sure what Suzanne is thinking of here, but date and calculation fields do work in mail merge. You need CTRL+F9 for *each pair* of curly brackets and you need to end up with the following { ={ DATE \@ "yyyy" } +1 } which currently will give you 2007. Press F9 to update the field. For more complex date calculations, see http://www.gmayor.com/insert_a_date_...than_today.htm and for formatting, see http://www.gmayor.com/formatting_word_fields.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Rhino wrote: So you're saying that there's no way to put the current year plus 1 (whatever the current year is when I run the mail merge) in each label of a set of labels? No way at all?? Are you sure? I find that surprising: Word seems pretty powerful and the task of putting a date on each label seems pretty trivial. By the way, I can put the current date on a label easily enough, it's just the result of adding 1 to the current year that is giving me trouble. Considering that you can calculate quantities like the current year plus 1 in other places within the document, why not do the same in a mail merge? By the way, I was able to get past the Syntax Error problem I reported earlier. I now have perfectly valid looking code that doesn't give me an error message: { DATE = {={DATE \@ yyyy} + 1}} However, although the expression seems to be calculating the current year plus 1, the result of the calculation always seems to be the current year NOT the current year plus 1. For what it's worth, I have tried umpteen variations of this formula, some of which used CREATEDATE instead of DATE and some of which used "yyyy" instead of yyyy, but I always get the current year, not current year plus 1. I've tried adding numbers much greater than 1 - on the theory that 1 might have been interpreted as 1 millisecond instead of 1 year in this expression - but even with huge numbers like 99999999999999999, the result of the addition is always the current year. "Suzanne S. Barnhill" wrote in message ... You did not mention a mail merge. Date fields are not compatible with mail merges. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... There's got to be some kind of a knack that I'm just not getting here. I tried doing a CTRL-F9 to produce a pair of heavy braces at the right point in my document. That worked. Then, when I pasted the exact string you provided in your note, including the spaces, that seemed to work too. But as soon as I pressed the "Propagate" icon on the Mail Merge toolbar, the spot where I had entered the field code said !Syntax Error, {. VENT I've been messing with this seemingly simple task of inputting a formula for calculating the next year for something like two hours and my head's getting sore from banging it on the wall. I seem to have tried every variation I can imagine of DATE, SET, =, and everything else I could think of and it inevitably gets me a syntax error!! What the heck is going on here?? I've done a Google search on the newsgroup and seen several variations of your suggestion supplied by various responders and none of them seem to have any followup questions, which gives the impression that the original poster had no problem using this formula in their documents. So why do I alone seem to have problems with this?? Is there some kind of document wide setting that has the wrong value or something?? /VENT For what it's worth, I've also tried doing Insert/Field, selecting =, then entering { DATE \@ "YYYY" } +1 in the Formula field, then choosing 0 as the number format. That doesn't work either. I've tried using lowercase "yyyy" instead of "YYYY". That didn't help. Everything leads me back to this Syntax Error. What boneheaded mistake am I making here? -- Rhino "Suzanne S. Barnhill" wrote in message ... No need for a QUOTE field. This works just fine for me (Word 2003) with this syntax: { = { DATE \@ "YYYY" } +1 } Note the spaces. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... I'm trying to put a field code into my Word 2002 document but having trouble getting the syntax just right. I want the field code to be replaced by the current year plus 1. Therefore, if the document is being generated today, I want the field code to put 2007 at a specifc place within my document. I know that the field code {DATE \@ "YYYY"} will give me the current year. I'm struggling with how to write the field code that will give me the next year. First of all, I'm not sure whether I can write an expression that adds 1 to year and display that result directly or whether I have to first transform that result to a character string. Second, I'm not sure how to get the result even as an integer. To get an integer result, I'm guessing that I have to use an = formula, something like this: {={DATE \@ "YYYY"}+1} To get a character string result, I'm guessing that I have to imbed all of that in a QUOTE, something like this: {QUOTE "{={DATE \@ "YYYY"} +1}/1 \@ "YYYY"} This last guess was inspired by the Help article on QUOTE. Unfortunately, I inevitably get a Syntax Error whenever I try to use either approach, no matter how carefully I try to write the field code. (I'm a veteran programmer and I know how important it is to get the syntax of a statement just right.) What's worse is that everytime I get the Syntax Error, the original field code is destroyed and I have to painstakingly type it all in again rather than just altering it and trying it again. Can anyone help me out? -- Rhino |
#13
Posted to microsoft.public.word.newusers
|
|||
|
|||
Need help with Field Codes
All of the braces, including the internal ones, need to be inserted by Word,
not by typing. You cannot do a field like this using Insert Field. -- Charles Kenyon Word New User FAQ & Web Directory: http://addbalance.com/word Intermediate User's Guide to Microsoft Word (supplemented version of Microsoft's Legal Users' Guide) http://addbalance.com/usersguide See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome! My criminal defense site: http://addbalance.com --------- --------- --------- --------- --------- --------- This message is posted to a newsgroup. Please post replies and questions to the newsgroup so that others can learn from my ignorance and your wisdom. "Rhino" wrote in message ... "Graham Mayor" wrote in message ... I'm not sure what Suzanne is thinking of here, but date and calculation fields do work in mail merge. You need CTRL+F9 for *each pair* of curly brackets and you need to end up with the following { ={ DATE \@ "yyyy" } +1 } which currently will give you 2007. Press F9 to update the field. Okay, now I'm officially baffled. :-) I tried your suggestion just now and it worked perfectly. I even tried changing the date on my computer, closed and reopened the document and found that the current year and the current year plus 1 were exactly as I wanted them to be. The reason I'm baffled is that I tried the same formula - and umpteen variations - yesterday and none of them worked correctly: they either gave me an error of some kind or they inevitably showed the current year, not the current year plus 1. I was getting REALLY frustrated by that experience and now everything works just as cleanly and simply as I had expected when I started playing with this formula. I'm completely at a loss to understand why none of this was working yesterday despite several hours of experimentation and now works perfectly today. Do you or Suzanne have any idea what the problem might have been yesterday? I have to believe that there is a rational explanation for this so I find myself wondering what it is. My guess is that the technique I used for entering the formula was flawed in some way. I tried entering the formula in several different ways yesterday: 1. I cut and pasted the formula, except for the outermost braces, directly into my document, specifically in the top left hand label. Then I selected the formula and hit CTRL-F9. 2. I positioned the insert point at the appropriate spot in the document, hit CTRL-F9, typed the = sign, hit CTRL-F9 again, typed the DATE \@ "yyyy" portion of the formula, moved my cursor past the inner closing brace, then typed +1 between the two closing braces. 3. I positioned the insert point at the appropriate spot in the document, clicked Insert/Field, selected = Formula, entered {DATE \@ "yyyy"}+1 in the formula field, clicked OK. Should all of these techniques work in Word 2002? Today, I used the second approach and it worked perfectly, as I said. But I'm sure I did the same thing, probably several times, yesterday and it did NOT work then. For more complex date calculations, see http://www.gmayor.com/insert_a_date_...than_today.htm and for formatting, see http://www.gmayor.com/formatting_word_fields.htm I had a look at your links and found that the first one refers to the Macropod article on advanced date handling. I found that yesterday via Google newsgroups and downloaded his demonstration document. I was using it to compute the next year but his formulas weren't working for me either, despite typing them meticulously. Now that I appear to be out of the Twilight Zone, I may give those another try, just to verify that they work as Macropod describes. The formallting article was also interesting and I may use some of those techniques in future documents, just as I used another of your articles to learn how to do mail merges earlier in the week. You've done a great job with your website! Thank you for taking the time to share your knowledge with those of us who are new to Word and still struggling a bit with some aspects of the product! -- Rhino Rhino wrote: So you're saying that there's no way to put the current year plus 1 (whatever the current year is when I run the mail merge) in each label of a set of labels? No way at all?? Are you sure? I find that surprising: Word seems pretty powerful and the task of putting a date on each label seems pretty trivial. By the way, I can put the current date on a label easily enough, it's just the result of adding 1 to the current year that is giving me trouble. Considering that you can calculate quantities like the current year plus 1 in other places within the document, why not do the same in a mail merge? By the way, I was able to get past the Syntax Error problem I reported earlier. I now have perfectly valid looking code that doesn't give me an error message: { DATE = {={DATE \@ yyyy} + 1}} However, although the expression seems to be calculating the current year plus 1, the result of the calculation always seems to be the current year NOT the current year plus 1. For what it's worth, I have tried umpteen variations of this formula, some of which used CREATEDATE instead of DATE and some of which used "yyyy" instead of yyyy, but I always get the current year, not current year plus 1. I've tried adding numbers much greater than 1 - on the theory that 1 might have been interpreted as 1 millisecond instead of 1 year in this expression - but even with huge numbers like 99999999999999999, the result of the addition is always the current year. "Suzanne S. Barnhill" wrote in message ... You did not mention a mail merge. Date fields are not compatible with mail merges. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... There's got to be some kind of a knack that I'm just not getting here. I tried doing a CTRL-F9 to produce a pair of heavy braces at the right point in my document. That worked. Then, when I pasted the exact string you provided in your note, including the spaces, that seemed to work too. But as soon as I pressed the "Propagate" icon on the Mail Merge toolbar, the spot where I had entered the field code said !Syntax Error, {. VENT I've been messing with this seemingly simple task of inputting a formula for calculating the next year for something like two hours and my head's getting sore from banging it on the wall. I seem to have tried every variation I can imagine of DATE, SET, =, and everything else I could think of and it inevitably gets me a syntax error!! What the heck is going on here?? I've done a Google search on the newsgroup and seen several variations of your suggestion supplied by various responders and none of them seem to have any followup questions, which gives the impression that the original poster had no problem using this formula in their documents. So why do I alone seem to have problems with this?? Is there some kind of document wide setting that has the wrong value or something?? /VENT For what it's worth, I've also tried doing Insert/Field, selecting =, then entering { DATE \@ "YYYY" } +1 in the Formula field, then choosing 0 as the number format. That doesn't work either. I've tried using lowercase "yyyy" instead of "YYYY". That didn't help. Everything leads me back to this Syntax Error. What boneheaded mistake am I making here? -- Rhino "Suzanne S. Barnhill" wrote in message ... No need for a QUOTE field. This works just fine for me (Word 2003) with this syntax: { = { DATE \@ "YYYY" } +1 } Note the spaces. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... I'm trying to put a field code into my Word 2002 document but having trouble getting the syntax just right. I want the field code to be replaced by the current year plus 1. Therefore, if the document is being generated today, I want the field code to put 2007 at a specifc place within my document. I know that the field code {DATE \@ "YYYY"} will give me the current year. I'm struggling with how to write the field code that will give me the next year. First of all, I'm not sure whether I can write an expression that adds 1 to year and display that result directly or whether I have to first transform that result to a character string. Second, I'm not sure how to get the result even as an integer. To get an integer result, I'm guessing that I have to use an = formula, something like this: {={DATE \@ "YYYY"}+1} To get a character string result, I'm guessing that I have to imbed all of that in a QUOTE, something like this: {QUOTE "{={DATE \@ "YYYY"} +1}/1 \@ "YYYY"} This last guess was inspired by the Help article on QUOTE. Unfortunately, I inevitably get a Syntax Error whenever I try to use either approach, no matter how carefully I try to write the field code. (I'm a veteran programmer and I know how important it is to get the syntax of a statement just right.) What's worse is that everytime I get the Syntax Error, the original field code is destroyed and I have to painstakingly type it all in again rather than just altering it and trying it again. Can anyone help me out? -- Rhino |
#14
Posted to microsoft.public.word.newusers
|
|||
|
|||
Need help with Field Codes
Have you actually tried this? I do not get the CreateDate of the merged
document. I get the CreateDate of the mail merge main document, as plain text. This is not the creation date of the merged document, so it does me no good. The field is in the document header; perhaps that makes a difference? It (and all the rest of the "heading" text) has to be in the header because this is a catalog/directory merge. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Graham Mayor" wrote in message ... I'm not really sure where you are going with this. The only way that it would matter if CREATEDATE was converted to plain text during the merge (which it is) would be if you wanted to reprint the merged document at a later date - when it is just as simple to remerge. Take the following example: from the merge document { CREATEDATE \@ "d MMM yyyy" } ... { ={ CREATEDATE \@ "yyyy"} + 1 } { DATE \@ "d MMM yyyy" } ... { ={ DATE \@ "yyyy" } + 1 } { MERGEFIELD MergeDate \@ "d MMM yyyy" } ... { ={ MERGEFIELD MergeDate \@ "yyyy" } +1 } In the merged document 18 Jun 2006 ... { =2006 + 1 } { DATE \@ "d MMM yyyy" } ... { ={ DATE \@ "yyyy" } + 1 } 30 Jun 2006 ... { =2006 +1 } Which prints as 18 Jun 2006 ... 2007 18 Jun 2006 ... 2007 30 Jun 2006 ... 2007 Re-reading your post, it seems to be that Createdate will do what you want. It produces the date that the *merged* document was created and doesn't update so there's no need for you to unlink it? Or have I missed something along the way? I never merge directly to the printer. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Suzanne S. Barnhill wrote: I've already backed off somewhat, but do try a CreateDate field, Graham, before you assert that "date" fields work in mail merges. If you can find a way to get that to work, I'd be grateful. Here's what I get: 1. CreateDate in mail merge main document shows creation date of said document. 2. Merged document shows CreateDate of mail merge main document as plain text (not a field). If I use a Date field instead, then the field is preserved in the merged output, but that's not what I want, though it's a step forward, since it's easier to Ctrl+Shift+F9 to unlink the field than to type the date in manually. The document in question is a list of phone numbers for the members of my Rotary club; I create a new list whenever the membership changes, so I want it to show the revision date. I guess maybe the SaveDate is what I need to shoot for (now that I know there is a possibility of getting some kind of date field to work). "Graham Mayor" wrote in message ... I'm not sure what Suzanne is thinking of here, but date and calculation fields do work in mail merge. You need CTRL+F9 for *each pair* of curly brackets and you need to end up with the following { ={ DATE \@ "yyyy" } +1 } which currently will give you 2007. Press F9 to update the field. For more complex date calculations, see http://www.gmayor.com/insert_a_date_...than_today.htm and for formatting, see http://www.gmayor.com/formatting_word_fields.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Rhino wrote: So you're saying that there's no way to put the current year plus 1 (whatever the current year is when I run the mail merge) in each label of a set of labels? No way at all?? Are you sure? I find that surprising: Word seems pretty powerful and the task of putting a date on each label seems pretty trivial. By the way, I can put the current date on a label easily enough, it's just the result of adding 1 to the current year that is giving me trouble. Considering that you can calculate quantities like the current year plus 1 in other places within the document, why not do the same in a mail merge? By the way, I was able to get past the Syntax Error problem I reported earlier. I now have perfectly valid looking code that doesn't give me an error message: { DATE = {={DATE \@ yyyy} + 1}} However, although the expression seems to be calculating the current year plus 1, the result of the calculation always seems to be the current year NOT the current year plus 1. For what it's worth, I have tried umpteen variations of this formula, some of which used CREATEDATE instead of DATE and some of which used "yyyy" instead of yyyy, but I always get the current year, not current year plus 1. I've tried adding numbers much greater than 1 - on the theory that 1 might have been interpreted as 1 millisecond instead of 1 year in this expression - but even with huge numbers like 99999999999999999, the result of the addition is always the current year. "Suzanne S. Barnhill" wrote in message ... You did not mention a mail merge. Date fields are not compatible with mail merges. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... There's got to be some kind of a knack that I'm just not getting here. I tried doing a CTRL-F9 to produce a pair of heavy braces at the right point in my document. That worked. Then, when I pasted the exact string you provided in your note, including the spaces, that seemed to work too. But as soon as I pressed the "Propagate" icon on the Mail Merge toolbar, the spot where I had entered the field code said !Syntax Error, {. VENT I've been messing with this seemingly simple task of inputting a formula for calculating the next year for something like two hours and my head's getting sore from banging it on the wall. I seem to have tried every variation I can imagine of DATE, SET, =, and everything else I could think of and it inevitably gets me a syntax error!! What the heck is going on here?? I've done a Google search on the newsgroup and seen several variations of your suggestion supplied by various responders and none of them seem to have any followup questions, which gives the impression that the original poster had no problem using this formula in their documents. So why do I alone seem to have problems with this?? Is there some kind of document wide setting that has the wrong value or something?? /VENT For what it's worth, I've also tried doing Insert/Field, selecting =, then entering { DATE \@ "YYYY" } +1 in the Formula field, then choosing 0 as the number format. That doesn't work either. I've tried using lowercase "yyyy" instead of "YYYY". That didn't help. Everything leads me back to this Syntax Error. What boneheaded mistake am I making here? -- Rhino "Suzanne S. Barnhill" wrote in message ... No need for a QUOTE field. This works just fine for me (Word 2003) with this syntax: { = { DATE \@ "YYYY" } +1 } Note the spaces. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... I'm trying to put a field code into my Word 2002 document but having trouble getting the syntax just right. I want the field code to be replaced by the current year plus 1. Therefore, if the document is being generated today, I want the field code to put 2007 at a specifc place within my document. I know that the field code {DATE \@ "YYYY"} will give me the current year. I'm struggling with how to write the field code that will give me the next year. First of all, I'm not sure whether I can write an expression that adds 1 to year and display that result directly or whether I have to first transform that result to a character string. Second, I'm not sure how to get the result even as an integer. To get an integer result, I'm guessing that I have to use an = formula, something like this: {={DATE \@ "YYYY"}+1} To get a character string result, I'm guessing that I have to imbed all of that in a QUOTE, something like this: {QUOTE "{={DATE \@ "YYYY"} +1}/1 \@ "YYYY"} This last guess was inspired by the Help article on QUOTE. Unfortunately, I inevitably get a Syntax Error whenever I try to use either approach, no matter how carefully I try to write the field code. (I'm a veteran programmer and I know how important it is to get the syntax of a statement just right.) What's worse is that everytime I get the Syntax Error, the original field code is destroyed and I have to painstakingly type it all in again rather than just altering it and trying it again. Can anyone help me out? -- Rhino |
#15
Posted to microsoft.public.word.newusers
|
|||
|
|||
Need help with Field Codes
Save the mailmerge main document as a template and use FileNew to create a
new mail merge main document when you need one. -- 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 "Suzanne S. Barnhill" wrote in message ... Have you actually tried this? I do not get the CreateDate of the merged document. I get the CreateDate of the mail merge main document, as plain text. This is not the creation date of the merged document, so it does me no good. The field is in the document header; perhaps that makes a difference? It (and all the rest of the "heading" text) has to be in the header because this is a catalog/directory merge. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Graham Mayor" wrote in message ... I'm not really sure where you are going with this. The only way that it would matter if CREATEDATE was converted to plain text during the merge (which it is) would be if you wanted to reprint the merged document at a later date - when it is just as simple to remerge. Take the following example: from the merge document { CREATEDATE \@ "d MMM yyyy" } ... { ={ CREATEDATE \@ "yyyy"} + 1 } { DATE \@ "d MMM yyyy" } ... { ={ DATE \@ "yyyy" } + 1 } { MERGEFIELD MergeDate \@ "d MMM yyyy" } ... { ={ MERGEFIELD MergeDate \@ "yyyy" } +1 } In the merged document 18 Jun 2006 ... { =2006 + 1 } { DATE \@ "d MMM yyyy" } ... { ={ DATE \@ "yyyy" } + 1 } 30 Jun 2006 ... { =2006 +1 } Which prints as 18 Jun 2006 ... 2007 18 Jun 2006 ... 2007 30 Jun 2006 ... 2007 Re-reading your post, it seems to be that Createdate will do what you want. It produces the date that the *merged* document was created and doesn't update so there's no need for you to unlink it? Or have I missed something along the way? I never merge directly to the printer. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Suzanne S. Barnhill wrote: I've already backed off somewhat, but do try a CreateDate field, Graham, before you assert that "date" fields work in mail merges. If you can find a way to get that to work, I'd be grateful. Here's what I get: 1. CreateDate in mail merge main document shows creation date of said document. 2. Merged document shows CreateDate of mail merge main document as plain text (not a field). If I use a Date field instead, then the field is preserved in the merged output, but that's not what I want, though it's a step forward, since it's easier to Ctrl+Shift+F9 to unlink the field than to type the date in manually. The document in question is a list of phone numbers for the members of my Rotary club; I create a new list whenever the membership changes, so I want it to show the revision date. I guess maybe the SaveDate is what I need to shoot for (now that I know there is a possibility of getting some kind of date field to work). "Graham Mayor" wrote in message ... I'm not sure what Suzanne is thinking of here, but date and calculation fields do work in mail merge. You need CTRL+F9 for *each pair* of curly brackets and you need to end up with the following { ={ DATE \@ "yyyy" } +1 } which currently will give you 2007. Press F9 to update the field. For more complex date calculations, see http://www.gmayor.com/insert_a_date_...than_today.htm and for formatting, see http://www.gmayor.com/formatting_word_fields.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Rhino wrote: So you're saying that there's no way to put the current year plus 1 (whatever the current year is when I run the mail merge) in each label of a set of labels? No way at all?? Are you sure? I find that surprising: Word seems pretty powerful and the task of putting a date on each label seems pretty trivial. By the way, I can put the current date on a label easily enough, it's just the result of adding 1 to the current year that is giving me trouble. Considering that you can calculate quantities like the current year plus 1 in other places within the document, why not do the same in a mail merge? By the way, I was able to get past the Syntax Error problem I reported earlier. I now have perfectly valid looking code that doesn't give me an error message: { DATE = {={DATE \@ yyyy} + 1}} However, although the expression seems to be calculating the current year plus 1, the result of the calculation always seems to be the current year NOT the current year plus 1. For what it's worth, I have tried umpteen variations of this formula, some of which used CREATEDATE instead of DATE and some of which used "yyyy" instead of yyyy, but I always get the current year, not current year plus 1. I've tried adding numbers much greater than 1 - on the theory that 1 might have been interpreted as 1 millisecond instead of 1 year in this expression - but even with huge numbers like 99999999999999999, the result of the addition is always the current year. "Suzanne S. Barnhill" wrote in message ... You did not mention a mail merge. Date fields are not compatible with mail merges. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... There's got to be some kind of a knack that I'm just not getting here. I tried doing a CTRL-F9 to produce a pair of heavy braces at the right point in my document. That worked. Then, when I pasted the exact string you provided in your note, including the spaces, that seemed to work too. But as soon as I pressed the "Propagate" icon on the Mail Merge toolbar, the spot where I had entered the field code said !Syntax Error, {. VENT I've been messing with this seemingly simple task of inputting a formula for calculating the next year for something like two hours and my head's getting sore from banging it on the wall. I seem to have tried every variation I can imagine of DATE, SET, =, and everything else I could think of and it inevitably gets me a syntax error!! What the heck is going on here?? I've done a Google search on the newsgroup and seen several variations of your suggestion supplied by various responders and none of them seem to have any followup questions, which gives the impression that the original poster had no problem using this formula in their documents. So why do I alone seem to have problems with this?? Is there some kind of document wide setting that has the wrong value or something?? /VENT For what it's worth, I've also tried doing Insert/Field, selecting =, then entering { DATE \@ "YYYY" } +1 in the Formula field, then choosing 0 as the number format. That doesn't work either. I've tried using lowercase "yyyy" instead of "YYYY". That didn't help. Everything leads me back to this Syntax Error. What boneheaded mistake am I making here? -- Rhino "Suzanne S. Barnhill" wrote in message ... No need for a QUOTE field. This works just fine for me (Word 2003) with this syntax: { = { DATE \@ "YYYY" } +1 } Note the spaces. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... I'm trying to put a field code into my Word 2002 document but having trouble getting the syntax just right. I want the field code to be replaced by the current year plus 1. Therefore, if the document is being generated today, I want the field code to put 2007 at a specifc place within my document. I know that the field code {DATE \@ "YYYY"} will give me the current year. I'm struggling with how to write the field code that will give me the next year. First of all, I'm not sure whether I can write an expression that adds 1 to year and display that result directly or whether I have to first transform that result to a character string. Second, I'm not sure how to get the result even as an integer. To get an integer result, I'm guessing that I have to use an = formula, something like this: {={DATE \@ "YYYY"}+1} To get a character string result, I'm guessing that I have to imbed all of that in a QUOTE, something like this: {QUOTE "{={DATE \@ "YYYY"} +1}/1 \@ "YYYY"} This last guess was inspired by the Help article on QUOTE. Unfortunately, I inevitably get a Syntax Error whenever I try to use either approach, no matter how carefully I try to write the field code. (I'm a veteran programmer and I know how important it is to get the syntax of a statement just right.) What's worse is that everytime I get the Syntax Error, the original field code is destroyed and I have to painstakingly type it all in again rather than just altering it and trying it again. Can anyone help me out? -- Rhino |
#16
Posted to microsoft.public.word.newusers
|
|||
|
|||
Need help with Field Codes
That would work.
-- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Doug Robbins - Word MVP" wrote in message ... Save the mailmerge main document as a template and use FileNew to create a new mail merge main document when you need one. -- 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 "Suzanne S. Barnhill" wrote in message ... Have you actually tried this? I do not get the CreateDate of the merged document. I get the CreateDate of the mail merge main document, as plain text. This is not the creation date of the merged document, so it does me no good. The field is in the document header; perhaps that makes a difference? It (and all the rest of the "heading" text) has to be in the header because this is a catalog/directory merge. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Graham Mayor" wrote in message ... I'm not really sure where you are going with this. The only way that it would matter if CREATEDATE was converted to plain text during the merge (which it is) would be if you wanted to reprint the merged document at a later date - when it is just as simple to remerge. Take the following example: from the merge document { CREATEDATE \@ "d MMM yyyy" } ... { ={ CREATEDATE \@ "yyyy"} + 1 } { DATE \@ "d MMM yyyy" } ... { ={ DATE \@ "yyyy" } + 1 } { MERGEFIELD MergeDate \@ "d MMM yyyy" } ... { ={ MERGEFIELD MergeDate \@ "yyyy" } +1 } In the merged document 18 Jun 2006 ... { =2006 + 1 } { DATE \@ "d MMM yyyy" } ... { ={ DATE \@ "yyyy" } + 1 } 30 Jun 2006 ... { =2006 +1 } Which prints as 18 Jun 2006 ... 2007 18 Jun 2006 ... 2007 30 Jun 2006 ... 2007 Re-reading your post, it seems to be that Createdate will do what you want. It produces the date that the *merged* document was created and doesn't update so there's no need for you to unlink it? Or have I missed something along the way? I never merge directly to the printer. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Suzanne S. Barnhill wrote: I've already backed off somewhat, but do try a CreateDate field, Graham, before you assert that "date" fields work in mail merges. If you can find a way to get that to work, I'd be grateful. Here's what I get: 1. CreateDate in mail merge main document shows creation date of said document. 2. Merged document shows CreateDate of mail merge main document as plain text (not a field). If I use a Date field instead, then the field is preserved in the merged output, but that's not what I want, though it's a step forward, since it's easier to Ctrl+Shift+F9 to unlink the field than to type the date in manually. The document in question is a list of phone numbers for the members of my Rotary club; I create a new list whenever the membership changes, so I want it to show the revision date. I guess maybe the SaveDate is what I need to shoot for (now that I know there is a possibility of getting some kind of date field to work). "Graham Mayor" wrote in message ... I'm not sure what Suzanne is thinking of here, but date and calculation fields do work in mail merge. You need CTRL+F9 for *each pair* of curly brackets and you need to end up with the following { ={ DATE \@ "yyyy" } +1 } which currently will give you 2007. Press F9 to update the field. For more complex date calculations, see http://www.gmayor.com/insert_a_date_...than_today.htm and for formatting, see http://www.gmayor.com/formatting_word_fields.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Rhino wrote: So you're saying that there's no way to put the current year plus 1 (whatever the current year is when I run the mail merge) in each label of a set of labels? No way at all?? Are you sure? I find that surprising: Word seems pretty powerful and the task of putting a date on each label seems pretty trivial. By the way, I can put the current date on a label easily enough, it's just the result of adding 1 to the current year that is giving me trouble. Considering that you can calculate quantities like the current year plus 1 in other places within the document, why not do the same in a mail merge? By the way, I was able to get past the Syntax Error problem I reported earlier. I now have perfectly valid looking code that doesn't give me an error message: { DATE = {={DATE \@ yyyy} + 1}} However, although the expression seems to be calculating the current year plus 1, the result of the calculation always seems to be the current year NOT the current year plus 1. For what it's worth, I have tried umpteen variations of this formula, some of which used CREATEDATE instead of DATE and some of which used "yyyy" instead of yyyy, but I always get the current year, not current year plus 1. I've tried adding numbers much greater than 1 - on the theory that 1 might have been interpreted as 1 millisecond instead of 1 year in this expression - but even with huge numbers like 99999999999999999, the result of the addition is always the current year. "Suzanne S. Barnhill" wrote in message ... You did not mention a mail merge. Date fields are not compatible with mail merges. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... There's got to be some kind of a knack that I'm just not getting here. I tried doing a CTRL-F9 to produce a pair of heavy braces at the right point in my document. That worked. Then, when I pasted the exact string you provided in your note, including the spaces, that seemed to work too. But as soon as I pressed the "Propagate" icon on the Mail Merge toolbar, the spot where I had entered the field code said !Syntax Error, {. VENT I've been messing with this seemingly simple task of inputting a formula for calculating the next year for something like two hours and my head's getting sore from banging it on the wall. I seem to have tried every variation I can imagine of DATE, SET, =, and everything else I could think of and it inevitably gets me a syntax error!! What the heck is going on here?? I've done a Google search on the newsgroup and seen several variations of your suggestion supplied by various responders and none of them seem to have any followup questions, which gives the impression that the original poster had no problem using this formula in their documents. So why do I alone seem to have problems with this?? Is there some kind of document wide setting that has the wrong value or something?? /VENT For what it's worth, I've also tried doing Insert/Field, selecting =, then entering { DATE \@ "YYYY" } +1 in the Formula field, then choosing 0 as the number format. That doesn't work either. I've tried using lowercase "yyyy" instead of "YYYY". That didn't help. Everything leads me back to this Syntax Error. What boneheaded mistake am I making here? -- Rhino "Suzanne S. Barnhill" wrote in message ... No need for a QUOTE field. This works just fine for me (Word 2003) with this syntax: { = { DATE \@ "YYYY" } +1 } Note the spaces. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... I'm trying to put a field code into my Word 2002 document but having trouble getting the syntax just right. I want the field code to be replaced by the current year plus 1. Therefore, if the document is being generated today, I want the field code to put 2007 at a specifc place within my document. I know that the field code {DATE \@ "YYYY"} will give me the current year. I'm struggling with how to write the field code that will give me the next year. First of all, I'm not sure whether I can write an expression that adds 1 to year and display that result directly or whether I have to first transform that result to a character string. Second, I'm not sure how to get the result even as an integer. To get an integer result, I'm guessing that I have to use an = formula, something like this: {={DATE \@ "YYYY"}+1} To get a character string result, I'm guessing that I have to imbed all of that in a QUOTE, something like this: {QUOTE "{={DATE \@ "YYYY"} +1}/1 \@ "YYYY"} This last guess was inspired by the Help article on QUOTE. Unfortunately, I inevitably get a Syntax Error whenever I try to use either approach, no matter how carefully I try to write the field code. (I'm a veteran programmer and I know how important it is to get the syntax of a statement just right.) What's worse is that everytime I get the Syntax Error, the original field code is destroyed and I have to painstakingly type it all in again rather than just altering it and trying it again. Can anyone help me out? -- Rhino |
#17
Posted to microsoft.public.word.newusers
|
|||
|
|||
Need help with Field Codes
I see your point - which was not revealed using a new merge document as the
createdate is today, but Doug has it covered -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Suzanne S. Barnhill wrote: Have you actually tried this? I do not get the CreateDate of the merged document. I get the CreateDate of the mail merge main document, as plain text. This is not the creation date of the merged document, so it does me no good. The field is in the document header; perhaps that makes a difference? It (and all the rest of the "heading" text) has to be in the header because this is a catalog/directory merge. "Graham Mayor" wrote in message ... I'm not really sure where you are going with this. The only way that it would matter if CREATEDATE was converted to plain text during the merge (which it is) would be if you wanted to reprint the merged document at a later date - when it is just as simple to remerge. Take the following example: from the merge document { CREATEDATE \@ "d MMM yyyy" } ... { ={ CREATEDATE \@ "yyyy"} + 1 } { DATE \@ "d MMM yyyy" } ... { ={ DATE \@ "yyyy" } + 1 } { MERGEFIELD MergeDate \@ "d MMM yyyy" } ... { ={ MERGEFIELD MergeDate \@ "yyyy" } +1 } In the merged document 18 Jun 2006 ... { =2006 + 1 } { DATE \@ "d MMM yyyy" } ... { ={ DATE \@ "yyyy" } + 1 } 30 Jun 2006 ... { =2006 +1 } Which prints as 18 Jun 2006 ... 2007 18 Jun 2006 ... 2007 30 Jun 2006 ... 2007 Re-reading your post, it seems to be that Createdate will do what you want. It produces the date that the *merged* document was created and doesn't update so there's no need for you to unlink it? Or have I missed something along the way? I never merge directly to the printer. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Suzanne S. Barnhill wrote: I've already backed off somewhat, but do try a CreateDate field, Graham, before you assert that "date" fields work in mail merges. If you can find a way to get that to work, I'd be grateful. Here's what I get: 1. CreateDate in mail merge main document shows creation date of said document. 2. Merged document shows CreateDate of mail merge main document as plain text (not a field). If I use a Date field instead, then the field is preserved in the merged output, but that's not what I want, though it's a step forward, since it's easier to Ctrl+Shift+F9 to unlink the field than to type the date in manually. The document in question is a list of phone numbers for the members of my Rotary club; I create a new list whenever the membership changes, so I want it to show the revision date. I guess maybe the SaveDate is what I need to shoot for (now that I know there is a possibility of getting some kind of date field to work). "Graham Mayor" wrote in message ... I'm not sure what Suzanne is thinking of here, but date and calculation fields do work in mail merge. You need CTRL+F9 for *each pair* of curly brackets and you need to end up with the following { ={ DATE \@ "yyyy" } +1 } which currently will give you 2007. Press F9 to update the field. For more complex date calculations, see http://www.gmayor.com/insert_a_date_...than_today.htm and for formatting, see http://www.gmayor.com/formatting_word_fields.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Rhino wrote: So you're saying that there's no way to put the current year plus 1 (whatever the current year is when I run the mail merge) in each label of a set of labels? No way at all?? Are you sure? I find that surprising: Word seems pretty powerful and the task of putting a date on each label seems pretty trivial. By the way, I can put the current date on a label easily enough, it's just the result of adding 1 to the current year that is giving me trouble. Considering that you can calculate quantities like the current year plus 1 in other places within the document, why not do the same in a mail merge? By the way, I was able to get past the Syntax Error problem I reported earlier. I now have perfectly valid looking code that doesn't give me an error message: { DATE = {={DATE \@ yyyy} + 1}} However, although the expression seems to be calculating the current year plus 1, the result of the calculation always seems to be the current year NOT the current year plus 1. For what it's worth, I have tried umpteen variations of this formula, some of which used CREATEDATE instead of DATE and some of which used "yyyy" instead of yyyy, but I always get the current year, not current year plus 1. I've tried adding numbers much greater than 1 - on the theory that 1 might have been interpreted as 1 millisecond instead of 1 year in this expression - but even with huge numbers like 99999999999999999, the result of the addition is always the current year. "Suzanne S. Barnhill" wrote in message ... You did not mention a mail merge. Date fields are not compatible with mail merges. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... There's got to be some kind of a knack that I'm just not getting here. I tried doing a CTRL-F9 to produce a pair of heavy braces at the right point in my document. That worked. Then, when I pasted the exact string you provided in your note, including the spaces, that seemed to work too. But as soon as I pressed the "Propagate" icon on the Mail Merge toolbar, the spot where I had entered the field code said !Syntax Error, {. VENT I've been messing with this seemingly simple task of inputting a formula for calculating the next year for something like two hours and my head's getting sore from banging it on the wall. I seem to have tried every variation I can imagine of DATE, SET, =, and everything else I could think of and it inevitably gets me a syntax error!! What the heck is going on here?? I've done a Google search on the newsgroup and seen several variations of your suggestion supplied by various responders and none of them seem to have any followup questions, which gives the impression that the original poster had no problem using this formula in their documents. So why do I alone seem to have problems with this?? Is there some kind of document wide setting that has the wrong value or something?? /VENT For what it's worth, I've also tried doing Insert/Field, selecting =, then entering { DATE \@ "YYYY" } +1 in the Formula field, then choosing 0 as the number format. That doesn't work either. I've tried using lowercase "yyyy" instead of "YYYY". That didn't help. Everything leads me back to this Syntax Error. What boneheaded mistake am I making here? -- Rhino "Suzanne S. Barnhill" wrote in message ... No need for a QUOTE field. This works just fine for me (Word 2003) with this syntax: { = { DATE \@ "YYYY" } +1 } Note the spaces. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Rhino" wrote in message ... I'm trying to put a field code into my Word 2002 document but having trouble getting the syntax just right. I want the field code to be replaced by the current year plus 1. Therefore, if the document is being generated today, I want the field code to put 2007 at a specifc place within my document. I know that the field code {DATE \@ "YYYY"} will give me the current year. I'm struggling with how to write the field code that will give me the next year. First of all, I'm not sure whether I can write an expression that adds 1 to year and display that result directly or whether I have to first transform that result to a character string. Second, I'm not sure how to get the result even as an integer. To get an integer result, I'm guessing that I have to use an = formula, something like this: {={DATE \@ "YYYY"}+1} To get a character string result, I'm guessing that I have to imbed all of that in a QUOTE, something like this: {QUOTE "{={DATE \@ "YYYY"} +1}/1 \@ "YYYY"} This last guess was inspired by the Help article on QUOTE. Unfortunately, I inevitably get a Syntax Error whenever I try to use either approach, no matter how carefully I try to write the field code. (I'm a veteran programmer and I know how important it is to get the syntax of a statement just right.) What's worse is that everytime I get the Syntax Error, the original field code is destroyed and I have to painstakingly type it all in again rather than just altering it and trying it again. Can anyone help me out? -- Rhino |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Hiding Field Codes | Microsoft Word Help | |||
How do I prevent field codes from displaying on merging? | Microsoft Word Help | |||
How do I prevent field codes from displaying on merging? | Mailmerge | |||
Secondary page numbering using field codes | Microsoft Word Help | |||
Field Codes | Microsoft Word Help |