Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Programatically determine number of sections
Hi,
The problem I have is this. I have a compound merge document that requires a report footer. The merged document will always vary in length and number of records merged. My solution was to try and determine the number of section breaks and use a mergefield something like the following: {IF {MERGEFIELD recID} = TotalNoOfSections "this text" "Blank"} It is not practical to enter the total number of sections manually. The Mergefield RecID always works with sequential numbers so in theory the total number of section will always equal the last merged record and trigger the report footer to show. This is merging from a database but can not be done as a database report. Any ideas? Regards Nick. |
#2
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Programatically determine number of sections
It is not clear how you want to cause the footer to show, but
ActiveDocument.Sections.Count will give the number of sections in a document. -- 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 "Biz Enhancer" wrote in message ... Hi, The problem I have is this. I have a compound merge document that requires a report footer. The merged document will always vary in length and number of records merged. My solution was to try and determine the number of section breaks and use a mergefield something like the following: {IF {MERGEFIELD recID} = TotalNoOfSections "this text" "Blank"} It is not practical to enter the total number of sections manually. The Mergefield RecID always works with sequential numbers so in theory the total number of section will always equal the last merged record and trigger the report footer to show. This is merging from a database but can not be done as a database report. Any ideas? Regards Nick. |
#3
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Programatically determine number of sections
Hi Biz Enhancer,
I don't think your proposed approach will work, since every Section is the last Section at the time it is created during a mailmerge. That and the mailmerge process outputs nothing of its own accord to indicate that the last record has been reached. However, there is a solution - you could use a field in the footer coded as: {IF{={NUMPAGES}-{PAGE}-{SECTIONPAGES}} 0 "Text for every page in the last Section"} Of course, if the Sections always had only one page, you could use the much simpler: {IF{NUMPAGES}= {PAGE} "Every Page in the last Section"} Note: The field brace pairs (ie '{ }') for the above examples are created via Ctrl-F9 - you can't simply type them or copy & paste them from this message. -- Cheers macropod [MVP - Microsoft Word] "Biz Enhancer" wrote in message ... Hi, The problem I have is this. I have a compound merge document that requires a report footer. The merged document will always vary in length and number of records merged. My solution was to try and determine the number of section breaks and use a mergefield something like the following: {IF {MERGEFIELD recID} = TotalNoOfSections "this text" "Blank"} It is not practical to enter the total number of sections manually. The Mergefield RecID always works with sequential numbers so in theory the total number of section will always equal the last merged record and trigger the report footer to show. This is merging from a database but can not be done as a database report. Any ideas? Regards Nick. |
#4
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Programatically determine number of sections
Do these actually work? I've tried various variations here and the
general impression I have is that at the point Word resolves the If statement, the values are never the ones you need. In Word 2007, Word seems to make the decision about which IF result to use right at the beginning of the merge - perhaps that's not the same for earlier versions. As long as you are outputting to a new document and have continuous page numbering (e.g. with a Directory merge) I think the following will work in recent versions of Word (2000 seems to get confused about NUMPAGES sometimes) { ={ NUMPAGES }-{ PAGE } \#";;'last page'" } { ={ NUMPAGES }-{ PAGE }-{ SECTIONPAGES } \#";'last section'" } This is primarily because Word does not resolve the nested fields when you do it this way. But of course that will only be OK if the text you want to insert is relatively small etc. Peter Jamieson http://tips.pjmsn.me.uk macropod wrote: Hi Biz Enhancer, I don't think your proposed approach will work, since every Section is the last Section at the time it is created during a mailmerge. That and the mailmerge process outputs nothing of its own accord to indicate that the last record has been reached. However, there is a solution - you could use a field in the footer coded as: {IF{={NUMPAGES}-{PAGE}-{SECTIONPAGES}} 0 "Text for every page in the last Section"} Of course, if the Sections always had only one page, you could use the much simpler: {IF{NUMPAGES}= {PAGE} "Every Page in the last Section"} Note: The field brace pairs (ie '{ }') for the above examples are created via Ctrl-F9 - you can't simply type them or copy & paste them from this message. |
#5
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Programatically determine number of sections
Hi Peter,
Since the field coding in this case is independent of the merge process (and the fields are thus not converted to plain text), they remain dynamic and continue to evaluate as more Sections are added to the document. As coded, the output will display in whatever happens to be the last Section only - add/delete a Section and the the display will re-set itself to the new last Section. -- Cheers macropod [MVP - Microsoft Word] "Peter Jamieson" wrote in message ... Do these actually work? I've tried various variations here and the general impression I have is that at the point Word resolves the If statement, the values are never the ones you need. In Word 2007, Word seems to make the decision about which IF result to use right at the beginning of the merge - perhaps that's not the same for earlier versions. As long as you are outputting to a new document and have continuous page numbering (e.g. with a Directory merge) I think the following will work in recent versions of Word (2000 seems to get confused about NUMPAGES sometimes) { ={ NUMPAGES }-{ PAGE } \#";;'last page'" } { ={ NUMPAGES }-{ PAGE }-{ SECTIONPAGES } \#";'last section'" } This is primarily because Word does not resolve the nested fields when you do it this way. But of course that will only be OK if the text you want to insert is relatively small etc. Peter Jamieson http://tips.pjmsn.me.uk macropod wrote: Hi Biz Enhancer, I don't think your proposed approach will work, since every Section is the last Section at the time it is created during a mailmerge. That and the mailmerge process outputs nothing of its own accord to indicate that the last record has been reached. However, there is a solution - you could use a field in the footer coded as: {IF{={NUMPAGES}-{PAGE}-{SECTIONPAGES}} 0 "Text for every page in the last Section"} Of course, if the Sections always had only one page, you could use the much simpler: {IF{NUMPAGES}= {PAGE} "Every Page in the last Section"} Note: The field brace pairs (ie '{ }') for the above examples are created via Ctrl-F9 - you can't simply type them or copy & paste them from this message. |
#6
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Programatically determine number of sections
Hi macropod,
Well, it looks as if the OP has found a solution, but... in this case is independent of the merge process ....sorry, I get the impression I've missed something really obvious, as I'm not sure what you mean by this. I can see that the IF fields would work if they survived the merge, but they don't. At least not here. The individual { PAGE }, { NUMPAGES } and { SECTIONPAGES } do survive if you insert them. So I'm wondering what makes the { IF } construct survive. AFAICS where you use an { = } and a numeric format switch, the nested field does survive. Best regards, Peter Jamieson http://tips.pjmsn.me.uk macropod wrote: Hi Peter, Since the field coding in this case is independent of the merge process (and the fields are thus not converted to plain text), they remain dynamic and continue to evaluate as more Sections are added to the document. As coded, the output will display in whatever happens to be the last Section only - add/delete a Section and the the display will re-set itself to the new last Section. |
#7
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Programatically determine number of sections
Hi Peter,
Ah, I see what you mean. I originally tested the field code with an ordinary document, not with a mailmerge document. The following construct does survive the merge process: {={NUMPAGES}-{PAGE}-{SECTIONPAGES} \# ";'Text for every page in the last Section'"} Note the need for the single quotes - otherwise the 'x' in 'Text' is misinterpreted. -- Cheers macropod [MVP - Microsoft Word] "Peter Jamieson" wrote in message ... Hi macropod, Well, it looks as if the OP has found a solution, but... in this case is independent of the merge process ...sorry, I get the impression I've missed something really obvious, as I'm not sure what you mean by this. I can see that the IF fields would work if they survived the merge, but they don't. At least not here. The individual { PAGE }, { NUMPAGES } and { SECTIONPAGES } do survive if you insert them. So I'm wondering what makes the { IF } construct survive. AFAICS where you use an { = } and a numeric format switch, the nested field does survive. Best regards, Peter Jamieson http://tips.pjmsn.me.uk macropod wrote: Hi Peter, Since the field coding in this case is independent of the merge process (and the fields are thus not converted to plain text), they remain dynamic and continue to evaluate as more Sections are added to the document. As coded, the output will display in whatever happens to be the last Section only - add/delete a Section and the the display will re-set itself to the new last Section. |
#8
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Programatically determine number of sections
Hi macropod,
Thanks for confirming that - I wondered whether you might have found some magical technique to preserve these fields! Peter Jamieson http://tips.pjmsn.me.uk macropod wrote: Hi Peter, Ah, I see what you mean. I originally tested the field code with an ordinary document, not with a mailmerge document. The following construct does survive the merge process: {={NUMPAGES}-{PAGE}-{SECTIONPAGES} \# ";'Text for every page in the last Section'"} Note the need for the single quotes - otherwise the 'x' in 'Text' is misinterpreted. |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I number pages in a document with several sections? | Microsoft Word Help | |||
How do I number pages in a document with several sections? | Microsoft Word Help | |||
how to determine the number of rows in a large Word table? | Microsoft Word Help | |||
How do I number pages differently in different sections of a doc? | Microsoft Word Help | |||
Can I make different sections have different pg. number locations | Microsoft Word Help |