Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Biz Enhancer Biz Enhancer is offline
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default 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   Report Post  
Posted to microsoft.public.word.mailmerge.fields
macropod[_2_] macropod[_2_] is offline
external usenet poster
 
Posts: 2,059
Default 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   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default 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   Report Post  
Posted to microsoft.public.word.mailmerge.fields
macropod[_2_] macropod[_2_] is offline
external usenet poster
 
Posts: 2,059
Default 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   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default 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   Report Post  
Posted to microsoft.public.word.mailmerge.fields
macropod[_2_] macropod[_2_] is offline
external usenet poster
 
Posts: 2,059
Default 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   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default 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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I number pages in a document with several sections? SHenighan Microsoft Word Help 4 December 17th 07 07:27 PM
How do I number pages in a document with several sections? SHenighan Microsoft Word Help 1 December 17th 07 07:01 PM
how to determine the number of rows in a large Word table? bob g in essex ct Microsoft Word Help 5 November 20th 06 12:19 PM
How do I number pages differently in different sections of a doc? borbo Microsoft Word Help 1 October 29th 06 09:48 PM
Can I make different sections have different pg. number locations Debbie Microsoft Word Help 2 October 8th 06 06:28 PM


All times are GMT +1. The time now is 06:43 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"