Mergefields, IF statements and section breaks

J

JAnderson

So if I insert a continuous section break at the end of a source document,
how do I unlink the header/footer? I thought it was only possible with a
Next Page break. Thanks!

macropod said:
Hi JAnderson,

Unless you want those blank pages, I don't see the need to have the Next Page Section breaks in your target document.

You can kill off the unwanted 'link to previous' scenarios by inserting a Continuous Section break at the end of your target
document and unlinking the new Section from the previous one.

--
Cheers
macropod
[MVP - Microsoft Word]


JAnderson said:
Yes, perfect- that works.

Okay, so after MUCH coaching from you, here's what I've got so far:

I am able to successfully merge my documents and Word retains all of the
formatting, headers, and footers. My target document is basically a 2-piece
document which looks like this (ignoring error handling for simplicity):

{INCLUDETEXT "C:\\My Documents\\Animals\\{MERGEFIELD ANIMAL}.doc"}
---Section break (next page)---

(one full blank page)

General information document begins here, multiple pages with headers/footers
---Section break (next page)---
(one full blank page)
(end of document)

To get to this point, I've found I need to have a section break at the very
end of every source document, and the header/footer at the beginning of any
source document cannot be entirely blank.

When I merge more than one record at a time, I am thus left with a lot of
blank or mostly-blank pages. Once merged: After my source document there is
the blank page (from the next page break) with headers/footers from the
source document. Then there is my 'general' document, after which I also
have a blank page. If the header in my subsequent source document is blank,
it will automatically activate 'link to previous', and I will obtain the
unwanted header from my prior document.

I guess my final question is how to merge these documents in a way that I
don't have to handle every document with such care- why should I need to have
next page breaks at the bottom of every source document just to force most of
the pages into the correct formatting? I find that I'm having nearly the
same problems that I did when I stuffed each of my documents into individual
IF statements.

Your solution is easily the most elegant, and I'm hoping there's some way
that I can set up my target document so as to avoid having to mess with each
individual source document.

Thanks as always,

macropod said:
Hi JAnderson,

For error handling, you can use code like:
{IF{INCLUDETEXT "C:\\My Documents\\Animals\\{MERGEFIELD ANIMAL}.doc"}= "Error!*" "" {INCLUDETEXT "C:\\My
Documents\\Animals\\{MERGEFIELD ANIMAL}.doc"}}
The IF test examines the INCLUDETEXT result and, if it starts with 'Error!' (which I assume your 'Animal.doc' won't), then the
INCLUDETEXT result is suppressed but you'll still get the body of the target document.

If you want to supress the target document too, you could use a SKIPIF field, as in:
{SKIPIF{INCLUDETEXT "C:\\My Documents\\Animals\\{MERGEFIELD ANIMAL}.doc"}= "Error!*"}

--
Cheers
macropod
[MVP - Microsoft Word]


I think I understand, using a slightly different methodology (no bookmarks).
But before I get there, I need some error handling.

Let's say my mergefield is "Panda", but for whatever reason, I don't have
any "Panda.doc", and I don't intend to have one. How can I use my
INCLUDETEXT field to return nothing at all if the document doesn't exist?
Currently, I get an error.

Your help has been invaluable on this. Thanks,

:

Hi JAnderson,

OK, that's easy enough:

With your source document, you can omit the last Section break I referred to. Now, format the 1st Section with your desired
source
document layout. Next, select that Section break and bookmark it (Insert|Bookmark). I'll assume you called it 'Layout'

Now, go to the very start of your target document, and insert an INCLUDTEXT/MERGEFIELD combination, coded along the lines of:
{INCLUDETEXT "C:\\My Documents\\Animals\\{MERGEFIELD ANIMAL}.doc" Layout}

That's all you need to force the target document to adopt the source document's layout.

--
Cheers
macropod
[MVP - Microsoft Word]


Ah, now I understand where the miscommunication is. My objective is to have
the target margin adopt whatever margins the source document has. In
essence, I want my target document to "become" the source document. Thus, if
I merge in the "Zebra" document with its 0.3" margins, I want my final
product to have 0.3" margins. My current problem is that my current setup
causes the target document to have 0.3" margins only on the first page, and
the rest reverts back to the default of the target document, with text
shifted aside.

I will try adding section breaks at the beginning and end of the source
documents, but I'm curious if you have any additional suggestion now that I
have a better idea what I'm talking about :)

Thanks so much for your help,

:

Hi JAnderson,

OK, the target document requires 1" margins before & after the souce document, but the source documents can have varying
margins.

So, for each source document:
.. insert a Section break at the very start of the document.
.. insert a Section break at the very end of the document.
and format the Sections thus created (ie the new Section 1 and the new last Section) with 1" margins, and give the rest of
the
source document whatever margins it requires. Also unlink the headers & footers for your new 2nd Section and last Section
in
to
source document from that document's previous Sections and delete the heading from the new 1st Section.

With this approach, I don't see any need for a Section break to follow the mergfields in your target document.

--
Cheers
macropod
[MVP - Microsoft Word]


Hmm... That seems problematic. Say my target document has 1" margins and no
header/footer. Then, for example:

Penguin.doc = 0.5" margins, header and footer present
Lions.doc = 0.75" top margin, 0.35" right margin, header present
Zebra.doc = 0.3" margins all around, no header or footer

Resulting merged document = 1" margins, except for page 1.

I was hoping that by setting the INCLUDETEXT field up this way I could just
have one document that would incorporate the formatting characteristics of
all of the source documents, but it seems what you are saying is that is not
possible? I'm not sure how I could even work around this limitation then,
and I thought I was so close. Am I reading this wrong? Thanks,

:

Oh, BTW, I should have mentioned that the 1st Section in the source document should be formatted with the same
attributes
as
the
target document.

--
Cheers
macropod
[MVP - Microsoft Word]


Hi JAnderson,

The symptoms you're describing suggest the source document has a different paper size than the target document.

As for indents & tabs, are you sure they're defined using the same defaults for both the source and target documents?

Do you think I should try a section break at the beginning AND end of the source documents?
Wouldn't hurt, especially if that Section break reverts the page layout settings to those used in the target document.

--
Cheers
macropod
[MVP - Microsoft Word]


From what you're describing, what I'm doing should work perfectly, you're
right. The best way I can describe what is going on is that only the first
page of my final product seems to observe the formatting; all remaining pages
revert to the target document's default settings. Furthermore, the text from
the source document does not line up with the indent arrows - instead it
falls off to the left of the page. It's very unusual. The same thing
happens with the header and footer on all pages after the first page.

Do you think I should try a section break at the beginning AND end of the
source documents? I'm SO close, I feel like I'm just missing one step.

Thanks again for all of your help,


:

Hi JAnderson,

Provided your:
.. source document (ie the one referenced by the INCLUDETEXT field) starts off with a Section break; and
.. target document (ie your mailmerge main document) has a Section break after the mergefields,
I don't believe the Section breaks in the source document will have any effect on the target document outside of
those
Section
breaks.

As for the partial shifting, are you sure the source and target documents have the same page formats (eg A4)?

--
Cheers
macropod
[MVP - Microsoft Word]


Ok, we're definitely getting closer - thank you! I did what you suggested by
placing a continuous section break at the beginning of my 'animal' documents,
and placed a section break after my INCLUDETEXT field.

Two problems:

1) Some of my 'animal' documents have multiple section breaks within the
document (separate footers, etc.). I'm not sure how this is affecting the
resulting document.

2) My resulting merged document only retains the correct formatting for the
first page, then reverts to the default formatting of the 'primary/host'
document. Furthermore, all text and headers/footers are shifted partially
off the visible area of the page (these are not unusual documents, just text
and some tables within the printable margins of a page).

I'm encouraged by the results so far; I really want to get to the point
where my INCLUDETEXT field can LITERALLY pull the entire document. All
mergefields within the INCLUDETEXT document are merging correctly, thankfully.

Any ideas why the formatting doesn't 'stick' on these documents? What about
adding a field switch to the INCLUDETEXT field, like *Charformat or something?

:

Hi JAnderson,

I think you'll get the results you're after if you make the first character of each of the 'animal' documents a
continuous
Section
break and if you insert a continuous Section break in your mailmerge document after the mergefields also.
Alternatively,
if
you
want
each of the 'animal' documents to start on a new page, and the mailmerge document to resume on a new page after
that,
make
the
section breaks 'next page'.

--
Cheers
macropod
[MVP - Microsoft Word]


Ah, that makes sense, thank you. It looks like the last of my problems is
formatting.

Each of my documents has different page setup dimensions (margins,
header/footer, etc.), by they seem to take on that of the main "host"
document, rather than keeping their original formatting. I can't think of a
way around this, but everything else is looking pretty good.

Any ideas? Thanks as always,


:

The point of the exercise was that you don't need the conditional
statements. The Includetext field inserts the appropriate document. And yes
you can put mergefields in the included documents and they will work
provided they match the fields in your data source.
 
M

macropod

Hi JAnderson,

No, you can unlink the headers attached to continuous breaks also. At most you might need to temporarily insert a page break after
the Section break to get to its header.

--
Cheers
macropod
[MVP - Microsoft Word]


JAnderson said:
So if I insert a continuous section break at the end of a source document,
how do I unlink the header/footer? I thought it was only possible with a
Next Page break. Thanks!

macropod said:
Hi JAnderson,

Unless you want those blank pages, I don't see the need to have the Next Page Section breaks in your target document.

You can kill off the unwanted 'link to previous' scenarios by inserting a Continuous Section break at the end of your target
document and unlinking the new Section from the previous one.

--
Cheers
macropod
[MVP - Microsoft Word]


JAnderson said:
Yes, perfect- that works.

Okay, so after MUCH coaching from you, here's what I've got so far:

I am able to successfully merge my documents and Word retains all of the
formatting, headers, and footers. My target document is basically a 2-piece
document which looks like this (ignoring error handling for simplicity):

{INCLUDETEXT "C:\\My Documents\\Animals\\{MERGEFIELD ANIMAL}.doc"}
---Section break (next page)---

(one full blank page)

General information document begins here, multiple pages with headers/footers
---Section break (next page)---
(one full blank page)
(end of document)

To get to this point, I've found I need to have a section break at the very
end of every source document, and the header/footer at the beginning of any
source document cannot be entirely blank.

When I merge more than one record at a time, I am thus left with a lot of
blank or mostly-blank pages. Once merged: After my source document there is
the blank page (from the next page break) with headers/footers from the
source document. Then there is my 'general' document, after which I also
have a blank page. If the header in my subsequent source document is blank,
it will automatically activate 'link to previous', and I will obtain the
unwanted header from my prior document.

I guess my final question is how to merge these documents in a way that I
don't have to handle every document with such care- why should I need to have
next page breaks at the bottom of every source document just to force most of
the pages into the correct formatting? I find that I'm having nearly the
same problems that I did when I stuffed each of my documents into individual
IF statements.

Your solution is easily the most elegant, and I'm hoping there's some way
that I can set up my target document so as to avoid having to mess with each
individual source document.

Thanks as always,

:

Hi JAnderson,

For error handling, you can use code like:
{IF{INCLUDETEXT "C:\\My Documents\\Animals\\{MERGEFIELD ANIMAL}.doc"}= "Error!*" "" {INCLUDETEXT "C:\\My
Documents\\Animals\\{MERGEFIELD ANIMAL}.doc"}}
The IF test examines the INCLUDETEXT result and, if it starts with 'Error!' (which I assume your 'Animal.doc' won't), then the
INCLUDETEXT result is suppressed but you'll still get the body of the target document.

If you want to supress the target document too, you could use a SKIPIF field, as in:
{SKIPIF{INCLUDETEXT "C:\\My Documents\\Animals\\{MERGEFIELD ANIMAL}.doc"}= "Error!*"}

--
Cheers
macropod
[MVP - Microsoft Word]


I think I understand, using a slightly different methodology (no bookmarks).
But before I get there, I need some error handling.

Let's say my mergefield is "Panda", but for whatever reason, I don't have
any "Panda.doc", and I don't intend to have one. How can I use my
INCLUDETEXT field to return nothing at all if the document doesn't exist?
Currently, I get an error.

Your help has been invaluable on this. Thanks,

:

Hi JAnderson,

OK, that's easy enough:

With your source document, you can omit the last Section break I referred to. Now, format the 1st Section with your desired
source
document layout. Next, select that Section break and bookmark it (Insert|Bookmark). I'll assume you called it 'Layout'

Now, go to the very start of your target document, and insert an INCLUDTEXT/MERGEFIELD combination, coded along the lines
of:
{INCLUDETEXT "C:\\My Documents\\Animals\\{MERGEFIELD ANIMAL}.doc" Layout}

That's all you need to force the target document to adopt the source document's layout.

--
Cheers
macropod
[MVP - Microsoft Word]


Ah, now I understand where the miscommunication is. My objective is to have
the target margin adopt whatever margins the source document has. In
essence, I want my target document to "become" the source document. Thus, if
I merge in the "Zebra" document with its 0.3" margins, I want my final
product to have 0.3" margins. My current problem is that my current setup
causes the target document to have 0.3" margins only on the first page, and
the rest reverts back to the default of the target document, with text
shifted aside.

I will try adding section breaks at the beginning and end of the source
documents, but I'm curious if you have any additional suggestion now that I
have a better idea what I'm talking about :)

Thanks so much for your help,

:

Hi JAnderson,

OK, the target document requires 1" margins before & after the souce document, but the source documents can have varying
margins.

So, for each source document:
.. insert a Section break at the very start of the document.
.. insert a Section break at the very end of the document.
and format the Sections thus created (ie the new Section 1 and the new last Section) with 1" margins, and give the rest
of
the
source document whatever margins it requires. Also unlink the headers & footers for your new 2nd Section and last
Section
in
to
source document from that document's previous Sections and delete the heading from the new 1st Section.

With this approach, I don't see any need for a Section break to follow the mergfields in your target document.

--
Cheers
macropod
[MVP - Microsoft Word]


Hmm... That seems problematic. Say my target document has 1" margins and no
header/footer. Then, for example:

Penguin.doc = 0.5" margins, header and footer present
Lions.doc = 0.75" top margin, 0.35" right margin, header present
Zebra.doc = 0.3" margins all around, no header or footer

Resulting merged document = 1" margins, except for page 1.

I was hoping that by setting the INCLUDETEXT field up this way I could just
have one document that would incorporate the formatting characteristics of
all of the source documents, but it seems what you are saying is that is not
possible? I'm not sure how I could even work around this limitation then,
and I thought I was so close. Am I reading this wrong? Thanks,

:

Oh, BTW, I should have mentioned that the 1st Section in the source document should be formatted with the same
attributes
as
the
target document.

--
Cheers
macropod
[MVP - Microsoft Word]


Hi JAnderson,

The symptoms you're describing suggest the source document has a different paper size than the target document.

As for indents & tabs, are you sure they're defined using the same defaults for both the source and target
documents?

Do you think I should try a section break at the beginning AND end of the source documents?
Wouldn't hurt, especially if that Section break reverts the page layout settings to those used in the target
document.

--
Cheers
macropod
[MVP - Microsoft Word]


From what you're describing, what I'm doing should work perfectly, you're
right. The best way I can describe what is going on is that only the first
page of my final product seems to observe the formatting; all remaining pages
revert to the target document's default settings. Furthermore, the text from
the source document does not line up with the indent arrows - instead it
falls off to the left of the page. It's very unusual. The same thing
happens with the header and footer on all pages after the first page.

Do you think I should try a section break at the beginning AND end of the
source documents? I'm SO close, I feel like I'm just missing one step.

Thanks again for all of your help,


:

Hi JAnderson,

Provided your:
.. source document (ie the one referenced by the INCLUDETEXT field) starts off with a Section break; and
.. target document (ie your mailmerge main document) has a Section break after the mergefields,
I don't believe the Section breaks in the source document will have any effect on the target document outside of
those
Section
breaks.

As for the partial shifting, are you sure the source and target documents have the same page formats (eg A4)?

--
Cheers
macropod
[MVP - Microsoft Word]


Ok, we're definitely getting closer - thank you! I did what you suggested by
placing a continuous section break at the beginning of my 'animal' documents,
and placed a section break after my INCLUDETEXT field.

Two problems:

1) Some of my 'animal' documents have multiple section breaks within the
document (separate footers, etc.). I'm not sure how this is affecting the
resulting document.

2) My resulting merged document only retains the correct formatting for the
first page, then reverts to the default formatting of the 'primary/host'
document. Furthermore, all text and headers/footers are shifted partially
off the visible area of the page (these are not unusual documents, just text
and some tables within the printable margins of a page).

I'm encouraged by the results so far; I really want to get to the point
where my INCLUDETEXT field can LITERALLY pull the entire document. All
mergefields within the INCLUDETEXT document are merging correctly, thankfully.

Any ideas why the formatting doesn't 'stick' on these documents? What about
adding a field switch to the INCLUDETEXT field, like *Charformat or something?

:

Hi JAnderson,

I think you'll get the results you're after if you make the first character of each of the 'animal' documents
a
continuous
Section
break and if you insert a continuous Section break in your mailmerge document after the mergefields also.
Alternatively,
if
you
want
each of the 'animal' documents to start on a new page, and the mailmerge document to resume on a new page
after
that,
make
the
section breaks 'next page'.

--
Cheers
macropod
[MVP - Microsoft Word]


Ah, that makes sense, thank you. It looks like the last of my problems is
formatting.

Each of my documents has different page setup dimensions (margins,
header/footer, etc.), by they seem to take on that of the main "host"
document, rather than keeping their original formatting. I can't think of a
way around this, but everything else is looking pretty good.

Any ideas? Thanks as always,


:

The point of the exercise was that you don't need the conditional
statements. The Includetext field inserts the appropriate document. And yes
you can put mergefields in the included documents and they will work
provided they match the fields in your data source.
 
S

Stan at Oak Ridge

I've been following this thread with great interest because I may soon want
to do something rather similar. I think that the actual goal is to have text
before and after the target information that takes on the margins, etc., of
the target document. So each letter has consistent margins and formatting,
but no two letters are necessarily the same.

Could you do it like this? Have an almost empty source document that does
an INCLUDETEXT ..mergefield all of the target documents. Then each target
document needs two INCLUDETEXT statements to put boilerplate text above and
below the target information. I'm not set up to try it yet -- can
INCLUDETEXT contain INCLUDETEXT, nested? This method requires editing all of
the target documents, which may be something that JAnderson is trying to
avoid.

Stan at Oak Ridge

macropod said:
Hi JAnderson,

OK, that's easy enough:

With your source document, you can omit the last Section break I referred to. Now, format the 1st Section with your desired source
document layout. Next, select that Section break and bookmark it (Insert|Bookmark). I'll assume you called it 'Layout'

Now, go to the very start of your target document, and insert an INCLUDTEXT/MERGEFIELD combination, coded along the lines of:
{INCLUDETEXT "C:\\My Documents\\Animals\\{MERGEFIELD ANIMAL}.doc" Layout}

That's all you need to force the target document to adopt the source document's layout.

--
Cheers
macropod
[MVP - Microsoft Word]


JAnderson said:
Ah, now I understand where the miscommunication is. My objective is to have
the target margin adopt whatever margins the source document has. In
essence, I want my target document to "become" the source document. Thus, if
I merge in the "Zebra" document with its 0.3" margins, I want my final
product to have 0.3" margins. My current problem is that my current setup
causes the target document to have 0.3" margins only on the first page, and
the rest reverts back to the default of the target document, with text
shifted aside.

I will try adding section breaks at the beginning and end of the source
documents, but I'm curious if you have any additional suggestion now that I
have a better idea what I'm talking about :)

Thanks so much for your help,

macropod said:
Hi JAnderson,

OK, the target document requires 1" margins before & after the souce document, but the source documents can have varying margins.

So, for each source document:
.. insert a Section break at the very start of the document.
.. insert a Section break at the very end of the document.
and format the Sections thus created (ie the new Section 1 and the new last Section) with 1" margins, and give the rest of the
source document whatever margins it requires. Also unlink the headers & footers for your new 2nd Section and last Section in to
source document from that document's previous Sections and delete the heading from the new 1st Section.

With this approach, I don't see any need for a Section break to follow the mergfields in your target document.

--
Cheers
macropod
[MVP - Microsoft Word]


Hmm... That seems problematic. Say my target document has 1" margins and no
header/footer. Then, for example:

Penguin.doc = 0.5" margins, header and footer present
Lions.doc = 0.75" top margin, 0.35" right margin, header present
Zebra.doc = 0.3" margins all around, no header or footer

Resulting merged document = 1" margins, except for page 1.

I was hoping that by setting the INCLUDETEXT field up this way I could just
have one document that would incorporate the formatting characteristics of
all of the source documents, but it seems what you are saying is that is not
possible? I'm not sure how I could even work around this limitation then,
and I thought I was so close. Am I reading this wrong? Thanks,

:

Oh, BTW, I should have mentioned that the 1st Section in the source document should be formatted with the same attributes as
the
target document.

--
Cheers
macropod
[MVP - Microsoft Word]


Hi JAnderson,

The symptoms you're describing suggest the source document has a different paper size than the target document.

As for indents & tabs, are you sure they're defined using the same defaults for both the source and target documents?

Do you think I should try a section break at the beginning AND end of the source documents?
Wouldn't hurt, especially if that Section break reverts the page layout settings to those used in the target document.

--
Cheers
macropod
[MVP - Microsoft Word]


From what you're describing, what I'm doing should work perfectly, you're
right. The best way I can describe what is going on is that only the first
page of my final product seems to observe the formatting; all remaining pages
revert to the target document's default settings. Furthermore, the text from
the source document does not line up with the indent arrows - instead it
falls off to the left of the page. It's very unusual. The same thing
happens with the header and footer on all pages after the first page.

Do you think I should try a section break at the beginning AND end of the
source documents? I'm SO close, I feel like I'm just missing one step.

Thanks again for all of your help,


:

Hi JAnderson,

Provided your:
.. source document (ie the one referenced by the INCLUDETEXT field) starts off with a Section break; and
.. target document (ie your mailmerge main document) has a Section break after the mergefields,
I don't believe the Section breaks in the source document will have any effect on the target document outside of those
Section
breaks.

As for the partial shifting, are you sure the source and target documents have the same page formats (eg A4)?

--
Cheers
macropod
[MVP - Microsoft Word]


Ok, we're definitely getting closer - thank you! I did what you suggested by
placing a continuous section break at the beginning of my 'animal' documents,
and placed a section break after my INCLUDETEXT field.

Two problems:

1) Some of my 'animal' documents have multiple section breaks within the
document (separate footers, etc.). I'm not sure how this is affecting the
resulting document.

2) My resulting merged document only retains the correct formatting for the
first page, then reverts to the default formatting of the 'primary/host'
document. Furthermore, all text and headers/footers are shifted partially
off the visible area of the page (these are not unusual documents, just text
and some tables within the printable margins of a page).

I'm encouraged by the results so far; I really want to get to the point
where my INCLUDETEXT field can LITERALLY pull the entire document. All
mergefields within the INCLUDETEXT document are merging correctly, thankfully.

Any ideas why the formatting doesn't 'stick' on these documents? What about
adding a field switch to the INCLUDETEXT field, like *Charformat or something?

:

Hi JAnderson,

I think you'll get the results you're after if you make the first character of each of the 'animal' documents a
continuous
Section
break and if you insert a continuous Section break in your mailmerge document after the mergefields also.
Alternatively,
if
you
want
each of the 'animal' documents to start on a new page, and the mailmerge document to resume on a new page after that,
make
the
section breaks 'next page'.

--
Cheers
macropod
[MVP - Microsoft Word]


Ah, that makes sense, thank you. It looks like the last of my problems is
formatting.

Each of my documents has different page setup dimensions (margins,
header/footer, etc.), by they seem to take on that of the main "host"
document, rather than keeping their original formatting. I can't think of a
way around this, but everything else is looking pretty good.

Any ideas? Thanks as always,


:

The point of the exercise was that you don't need the conditional
statements. The Includetext field inserts the appropriate document. And yes
you can put mergefields in the included documents and they will work
provided they match the fields in your data source.

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


JAnderson wrote:
Hmm... So could I still use conditional statements with INCLUDETEXT?
If my database record is 'zebra', I only want my zebra document to
show.

Also, would includetext retain formatting? It's important that I keep
margins, footers, and text formatting in a certain way.

Lastly, can INCLUDETEXT also accommodate mergefields? For example,
inside my zebra document are mergefields like 'zoo name' 'zoo
address' 'zoo city', etc., which merge from my database. This works
inside IF statements, but I wonder if it would with INCLUDETEXT...

Thanks,

:

Hi JAnderson,

You'd probably get better results by creating a separate reference
document for each scenario, then embedding your MERGEFIELD within an
INCLUDETEXT field pointing to the folder where those documents can
be found.

For example, suppose your refrence documents are in the folder C:\My
Documents\Animals and you have a series of files (eg Bear.doc,
Zebra.doc, etc) in that folder. In that case you could use an
INCLUDETEXT field coded as: {INCLUDETEXT "C:\\My
Documents\\Animals\\{MERGEFIELD ANIMAL}.doc"}

Now, if you add a new 'Animal' to your database, all you need to do
is to create a corresponding reference document for it in the folder
C:\My Documents\Animals.

--
Cheers
macropod
[MVP - Microsoft Word]


Ok, this is a somewhat complicated one, so bear with me:

I have a large document where each page is an "IF" statement
followed by a next-page section break. Let's pretend that I'm
using the merge field "Animal" as my condition:

{IF{MERGEFIELD_ANIMAL}= "BEAR" "
Document relating to bears
More text, formatting of 0.5" margins
More text
---section break (next page)---
" ""}
{IF{MERGEFIELD_ANIMAL}= "ZEBRA" "
Document relating to zebras
More text, formatting of 1" margins
More text
---section break (next page)---
" ""}
BEGIN REGULAR 2-PAGE DOCUMENT
More text, 1.2" margins
More text
End of document

Thus, if the condition "Bear" is met, then a document relating to
bears will become part of my document, otherwise, nothing happens
(the false condition is ""). Likewise, if "Zebra" is the value of
the field, then a document about zebras appears. Under any
condition, however, my "regular" document is always part of the
merge (say, a fact sheet about zoo animals).

This method, while potentially inelegant, works for our specific
needs, and works without any problems. However, there becomes a
point where inserting one more "IF" statement will "break" the
whole document.

Say I realize that I need to add yet another document about Lions,
so I follow the formatting above and enter this Lion IF statement
right after the zebra IF statement. For some reason, headers,
footers and margins (section break qualities) will not be correct
for whatever document I merge, and sometimes the "next page"
section breaks will reorient themselves as "continuous", thus
melding pages together.

I'm a bit stuck at this point, because I can't understand why, if a
section break is within an IF statement, it would later become
functional even though its condition is not met. Would it be more
effective if, every time I added a new IF statement, I re-built the
 
M

macropod

Hi Stan,

Yes, I suppose that would be feasible, but I don't see what you'd gain over having the boilerplate text in the target document. The
main issue for JAnderson is that the target document's layout has to be changed to match the source documents. With the approach
I've taken, There's only one document whose INCLUDTEXT paths would need to be updated if the process is moved to another
folder/server. Putting INCLUDTEXT fields in all the target documents, would require editing all of them too in such a scenario.

--
Cheers
macropod
[MVP - Microsoft Word]


Stan at Oak Ridge said:
I've been following this thread with great interest because I may soon want
to do something rather similar. I think that the actual goal is to have text
before and after the target information that takes on the margins, etc., of
the target document. So each letter has consistent margins and formatting,
but no two letters are necessarily the same.

Could you do it like this? Have an almost empty source document that does
an INCLUDETEXT ..mergefield all of the target documents. Then each target
document needs two INCLUDETEXT statements to put boilerplate text above and
below the target information. I'm not set up to try it yet -- can
INCLUDETEXT contain INCLUDETEXT, nested? This method requires editing all of
the target documents, which may be something that JAnderson is trying to
avoid.

Stan at Oak Ridge

macropod said:
Hi JAnderson,

OK, that's easy enough:

With your source document, you can omit the last Section break I referred to. Now, format the 1st Section with your desired
source
document layout. Next, select that Section break and bookmark it (Insert|Bookmark). I'll assume you called it 'Layout'

Now, go to the very start of your target document, and insert an INCLUDTEXT/MERGEFIELD combination, coded along the lines of:
{INCLUDETEXT "C:\\My Documents\\Animals\\{MERGEFIELD ANIMAL}.doc" Layout}

That's all you need to force the target document to adopt the source document's layout.

--
Cheers
macropod
[MVP - Microsoft Word]


JAnderson said:
Ah, now I understand where the miscommunication is. My objective is to have
the target margin adopt whatever margins the source document has. In
essence, I want my target document to "become" the source document. Thus, if
I merge in the "Zebra" document with its 0.3" margins, I want my final
product to have 0.3" margins. My current problem is that my current setup
causes the target document to have 0.3" margins only on the first page, and
the rest reverts back to the default of the target document, with text
shifted aside.

I will try adding section breaks at the beginning and end of the source
documents, but I'm curious if you have any additional suggestion now that I
have a better idea what I'm talking about :)

Thanks so much for your help,

:

Hi JAnderson,

OK, the target document requires 1" margins before & after the souce document, but the source documents can have varying
margins.

So, for each source document:
.. insert a Section break at the very start of the document.
.. insert a Section break at the very end of the document.
and format the Sections thus created (ie the new Section 1 and the new last Section) with 1" margins, and give the rest of the
source document whatever margins it requires. Also unlink the headers & footers for your new 2nd Section and last Section in
to
source document from that document's previous Sections and delete the heading from the new 1st Section.

With this approach, I don't see any need for a Section break to follow the mergfields in your target document.

--
Cheers
macropod
[MVP - Microsoft Word]


Hmm... That seems problematic. Say my target document has 1" margins and no
header/footer. Then, for example:

Penguin.doc = 0.5" margins, header and footer present
Lions.doc = 0.75" top margin, 0.35" right margin, header present
Zebra.doc = 0.3" margins all around, no header or footer

Resulting merged document = 1" margins, except for page 1.

I was hoping that by setting the INCLUDETEXT field up this way I could just
have one document that would incorporate the formatting characteristics of
all of the source documents, but it seems what you are saying is that is not
possible? I'm not sure how I could even work around this limitation then,
and I thought I was so close. Am I reading this wrong? Thanks,

:

Oh, BTW, I should have mentioned that the 1st Section in the source document should be formatted with the same attributes
as
the
target document.

--
Cheers
macropod
[MVP - Microsoft Word]


Hi JAnderson,

The symptoms you're describing suggest the source document has a different paper size than the target document.

As for indents & tabs, are you sure they're defined using the same defaults for both the source and target documents?

Do you think I should try a section break at the beginning AND end of the source documents?
Wouldn't hurt, especially if that Section break reverts the page layout settings to those used in the target document.

--
Cheers
macropod
[MVP - Microsoft Word]


From what you're describing, what I'm doing should work perfectly, you're
right. The best way I can describe what is going on is that only the first
page of my final product seems to observe the formatting; all remaining pages
revert to the target document's default settings. Furthermore, the text from
the source document does not line up with the indent arrows - instead it
falls off to the left of the page. It's very unusual. The same thing
happens with the header and footer on all pages after the first page.

Do you think I should try a section break at the beginning AND end of the
source documents? I'm SO close, I feel like I'm just missing one step.

Thanks again for all of your help,


:

Hi JAnderson,

Provided your:
.. source document (ie the one referenced by the INCLUDETEXT field) starts off with a Section break; and
.. target document (ie your mailmerge main document) has a Section break after the mergefields,
I don't believe the Section breaks in the source document will have any effect on the target document outside of those
Section
breaks.

As for the partial shifting, are you sure the source and target documents have the same page formats (eg A4)?

--
Cheers
macropod
[MVP - Microsoft Word]


Ok, we're definitely getting closer - thank you! I did what you suggested by
placing a continuous section break at the beginning of my 'animal' documents,
and placed a section break after my INCLUDETEXT field.

Two problems:

1) Some of my 'animal' documents have multiple section breaks within the
document (separate footers, etc.). I'm not sure how this is affecting the
resulting document.

2) My resulting merged document only retains the correct formatting for the
first page, then reverts to the default formatting of the 'primary/host'
document. Furthermore, all text and headers/footers are shifted partially
off the visible area of the page (these are not unusual documents, just text
and some tables within the printable margins of a page).

I'm encouraged by the results so far; I really want to get to the point
where my INCLUDETEXT field can LITERALLY pull the entire document. All
mergefields within the INCLUDETEXT document are merging correctly, thankfully.

Any ideas why the formatting doesn't 'stick' on these documents? What about
adding a field switch to the INCLUDETEXT field, like *Charformat or something?

:

Hi JAnderson,

I think you'll get the results you're after if you make the first character of each of the 'animal' documents a
continuous
Section
break and if you insert a continuous Section break in your mailmerge document after the mergefields also.
Alternatively,
if
you
want
each of the 'animal' documents to start on a new page, and the mailmerge document to resume on a new page after
that,
make
the
section breaks 'next page'.

--
Cheers
macropod
[MVP - Microsoft Word]


Ah, that makes sense, thank you. It looks like the last of my problems is
formatting.

Each of my documents has different page setup dimensions (margins,
header/footer, etc.), by they seem to take on that of the main "host"
document, rather than keeping their original formatting. I can't think of a
way around this, but everything else is looking pretty good.

Any ideas? Thanks as always,


:

The point of the exercise was that you don't need the conditional
statements. The Includetext field inserts the appropriate document. And yes
you can put mergefields in the included documents and they will work
provided they match the fields in your data source.

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


JAnderson wrote:
Hmm... So could I still use conditional statements with INCLUDETEXT?
If my database record is 'zebra', I only want my zebra document to
show.

Also, would includetext retain formatting? It's important that I keep
margins, footers, and text formatting in a certain way.

Lastly, can INCLUDETEXT also accommodate mergefields? For example,
inside my zebra document are mergefields like 'zoo name' 'zoo
address' 'zoo city', etc., which merge from my database. This works
inside IF statements, but I wonder if it would with INCLUDETEXT...

Thanks,

:

Hi JAnderson,

You'd probably get better results by creating a separate reference
document for each scenario, then embedding your MERGEFIELD within an
INCLUDETEXT field pointing to the folder where those documents can
be found.

For example, suppose your refrence documents are in the folder C:\My
Documents\Animals and you have a series of files (eg Bear.doc,
Zebra.doc, etc) in that folder. In that case you could use an
INCLUDETEXT field coded as: {INCLUDETEXT "C:\\My
Documents\\Animals\\{MERGEFIELD ANIMAL}.doc"}

Now, if you add a new 'Animal' to your database, all you need to do
is to create a corresponding reference document for it in the folder
C:\My Documents\Animals.

--
Cheers
macropod
[MVP - Microsoft Word]


Ok, this is a somewhat complicated one, so bear with me:

I have a large document where each page is an "IF" statement
followed by a next-page section break. Let's pretend that I'm
using the merge field "Animal" as my condition:

{IF{MERGEFIELD_ANIMAL}= "BEAR" "
Document relating to bears
More text, formatting of 0.5" margins
More text
---section break (next page)---
" ""}
{IF{MERGEFIELD_ANIMAL}= "ZEBRA" "
Document relating to zebras
More text, formatting of 1" margins
More text
---section break (next page)---
" ""}
BEGIN REGULAR 2-PAGE DOCUMENT
More text, 1.2" margins
More text
End of document

Thus, if the condition "Bear" is met, then a document relating to
bears will become part of my document, otherwise, nothing happens
(the false condition is ""). Likewise, if "Zebra" is the value of
the field, then a document about zebras appears. Under any
condition, however, my "regular" document is always part of the
merge (say, a fact sheet about zoo animals).

This method, while potentially inelegant, works for our specific
needs, and works without any problems. However, there becomes a
point where inserting one more "IF" statement will "break" the
whole document.

Say I realize that I need to add yet another document about Lions,
so I follow the formatting above and enter this Lion IF statement
right after the zebra IF statement. For some reason, headers,
footers and margins (section break qualities) will not be correct
for whatever document I merge, and sometimes the "next page"
section breaks will reorient themselves as "continuous", thus
melding pages together.

I'm a bit stuck at this point, because I can't understand why, if a
section break is within an IF statement, it would later become
functional even though its condition is not met. Would it be more
effective if, every time I added a new IF statement, I re-built the
 
S

Stan at Oak Ridge

Hi macropod,

Oh... I've been saying source when I should say target, and vice-versa.
Now it all makes sense.

Thanks!

Stan at Oak Ridge

macropod said:
Hi Stan,

Yes, I suppose that would be feasible, but I don't see what you'd gain over having the boilerplate text in the target document. The
main issue for JAnderson is that the target document's layout has to be changed to match the source documents. With the approach
I've taken, There's only one document whose INCLUDTEXT paths would need to be updated if the process is moved to another
folder/server. Putting INCLUDTEXT fields in all the target documents, would require editing all of them too in such a scenario.

--
Cheers
macropod
[MVP - Microsoft Word]


Stan at Oak Ridge said:
I've been following this thread with great interest because I may soon want
to do something rather similar. I think that the actual goal is to have text
before and after the target information that takes on the margins, etc., of
the target document. So each letter has consistent margins and formatting,
but no two letters are necessarily the same.

Could you do it like this? Have an almost empty source document that does
an INCLUDETEXT ..mergefield all of the target documents. Then each target
document needs two INCLUDETEXT statements to put boilerplate text above and
below the target information. I'm not set up to try it yet -- can
INCLUDETEXT contain INCLUDETEXT, nested? This method requires editing all of
the target documents, which may be something that JAnderson is trying to
avoid.

Stan at Oak Ridge

macropod said:
Hi JAnderson,

OK, that's easy enough:

With your source document, you can omit the last Section break I referred to. Now, format the 1st Section with your desired
source
document layout. Next, select that Section break and bookmark it (Insert|Bookmark). I'll assume you called it 'Layout'

Now, go to the very start of your target document, and insert an INCLUDTEXT/MERGEFIELD combination, coded along the lines of:
{INCLUDETEXT "C:\\My Documents\\Animals\\{MERGEFIELD ANIMAL}.doc" Layout}

That's all you need to force the target document to adopt the source document's layout.

--
Cheers
macropod
[MVP - Microsoft Word]


Ah, now I understand where the miscommunication is. My objective is to have
the target margin adopt whatever margins the source document has. In
essence, I want my target document to "become" the source document. Thus, if
I merge in the "Zebra" document with its 0.3" margins, I want my final
product to have 0.3" margins. My current problem is that my current setup
causes the target document to have 0.3" margins only on the first page, and
the rest reverts back to the default of the target document, with text
shifted aside.

I will try adding section breaks at the beginning and end of the source
documents, but I'm curious if you have any additional suggestion now that I
have a better idea what I'm talking about :)

Thanks so much for your help,

:

Hi JAnderson,

OK, the target document requires 1" margins before & after the souce document, but the source documents can have varying
margins.

So, for each source document:
.. insert a Section break at the very start of the document.
.. insert a Section break at the very end of the document.
and format the Sections thus created (ie the new Section 1 and the new last Section) with 1" margins, and give the rest of the
source document whatever margins it requires. Also unlink the headers & footers for your new 2nd Section and last Section in
to
source document from that document's previous Sections and delete the heading from the new 1st Section.

With this approach, I don't see any need for a Section break to follow the mergfields in your target document.

--
Cheers
macropod
[MVP - Microsoft Word]


Hmm... That seems problematic. Say my target document has 1" margins and no
header/footer. Then, for example:

Penguin.doc = 0.5" margins, header and footer present
Lions.doc = 0.75" top margin, 0.35" right margin, header present
Zebra.doc = 0.3" margins all around, no header or footer

Resulting merged document = 1" margins, except for page 1.

I was hoping that by setting the INCLUDETEXT field up this way I could just
have one document that would incorporate the formatting characteristics of
all of the source documents, but it seems what you are saying is that is not
possible? I'm not sure how I could even work around this limitation then,
and I thought I was so close. Am I reading this wrong? Thanks,

:

Oh, BTW, I should have mentioned that the 1st Section in the source document should be formatted with the same attributes
as
the
target document.

--
Cheers
macropod
[MVP - Microsoft Word]


Hi JAnderson,

The symptoms you're describing suggest the source document has a different paper size than the target document.

As for indents & tabs, are you sure they're defined using the same defaults for both the source and target documents?

Do you think I should try a section break at the beginning AND end of the source documents?
Wouldn't hurt, especially if that Section break reverts the page layout settings to those used in the target document.

--
Cheers
macropod
[MVP - Microsoft Word]


From what you're describing, what I'm doing should work perfectly, you're
right. The best way I can describe what is going on is that only the first
page of my final product seems to observe the formatting; all remaining pages
revert to the target document's default settings. Furthermore, the text from
the source document does not line up with the indent arrows - instead it
falls off to the left of the page. It's very unusual. The same thing
happens with the header and footer on all pages after the first page.

Do you think I should try a section break at the beginning AND end of the
source documents? I'm SO close, I feel like I'm just missing one step.

Thanks again for all of your help,


:

Hi JAnderson,

Provided your:
.. source document (ie the one referenced by the INCLUDETEXT field) starts off with a Section break; and
.. target document (ie your mailmerge main document) has a Section break after the mergefields,
I don't believe the Section breaks in the source document will have any effect on the target document outside of those
Section
breaks.

As for the partial shifting, are you sure the source and target documents have the same page formats (eg A4)?

--
Cheers
macropod
[MVP - Microsoft Word]


Ok, we're definitely getting closer - thank you! I did what you suggested by
placing a continuous section break at the beginning of my 'animal' documents,
and placed a section break after my INCLUDETEXT field.

Two problems:

1) Some of my 'animal' documents have multiple section breaks within the
document (separate footers, etc.). I'm not sure how this is affecting the
resulting document.

2) My resulting merged document only retains the correct formatting for the
first page, then reverts to the default formatting of the 'primary/host'
document. Furthermore, all text and headers/footers are shifted partially
off the visible area of the page (these are not unusual documents, just text
and some tables within the printable margins of a page).

I'm encouraged by the results so far; I really want to get to the point
where my INCLUDETEXT field can LITERALLY pull the entire document. All
mergefields within the INCLUDETEXT document are merging correctly, thankfully.

Any ideas why the formatting doesn't 'stick' on these documents? What about
adding a field switch to the INCLUDETEXT field, like *Charformat or something?

:

Hi JAnderson,

I think you'll get the results you're after if you make the first character of each of the 'animal' documents a
continuous
Section
break and if you insert a continuous Section break in your mailmerge document after the mergefields also.
Alternatively,
if
you
want
each of the 'animal' documents to start on a new page, and the mailmerge document to resume on a new page after
that,
make
the
section breaks 'next page'.

--
Cheers
macropod
[MVP - Microsoft Word]


Ah, that makes sense, thank you. It looks like the last of my problems is
formatting.

Each of my documents has different page setup dimensions (margins,
header/footer, etc.), by they seem to take on that of the main "host"
document, rather than keeping their original formatting. I can't think of a
way around this, but everything else is looking pretty good.

Any ideas? Thanks as always,


:

The point of the exercise was that you don't need the conditional
statements. The Includetext field inserts the appropriate document. And yes
you can put mergefields in the included documents and they will work
provided they match the fields in your data source.

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


JAnderson wrote:
Hmm... So could I still use conditional statements with INCLUDETEXT?
If my database record is 'zebra', I only want my zebra document to
show.

Also, would includetext retain formatting? It's important that I keep
margins, footers, and text formatting in a certain way.

Lastly, can INCLUDETEXT also accommodate mergefields? For example,
inside my zebra document are mergefields like 'zoo name' 'zoo
address' 'zoo city', etc., which merge from my database. This works
inside IF statements, but I wonder if it would with INCLUDETEXT...

Thanks,

:

Hi JAnderson,

You'd probably get better results by creating a separate reference
document for each scenario, then embedding your MERGEFIELD within an
INCLUDETEXT field pointing to the folder where those documents can
be found.

For example, suppose your refrence documents are in the folder C:\My
Documents\Animals and you have a series of files (eg Bear.doc,
Zebra.doc, etc) in that folder. In that case you could use an
INCLUDETEXT field coded as: {INCLUDETEXT "C:\\My
Documents\\Animals\\{MERGEFIELD ANIMAL}.doc"}

Now, if you add a new 'Animal' to your database, all you need to do
is to create a corresponding reference document for it in the folder
C:\My Documents\Animals.

--
Cheers
macropod
[MVP - Microsoft Word]


Ok, this is a somewhat complicated one, so bear with me:

I have a large document where each page is an "IF" statement
followed by a next-page section break. Let's pretend that I'm
using the merge field "Animal" as my condition:

{IF{MERGEFIELD_ANIMAL}= "BEAR" "
Document relating to bears
More text, formatting of 0.5" margins
 
N

Nicole Knapp

I have read this entire thread with interest because I am trying to do
something similar, though more simple.

I have a document that uses a mail merge. I created the IF statement, with
the INSERTTEXT field and a next page break. But it will not open the file.

The file is buried pretty deep on a network server - but in the same folder
as the original document.
Both documents and folders leading to the documents have spaces in their
filenames. I tried replacing the spaces with underscores - but no luck.

This is my statement:
{IF {MERGEFIELD course} = “Course D†"{INCLUDETEXT
"J:\\Dept\\staff\\2009\\letter_Page_3.doc"}" ""}

I am using the letter drive, not the network drive name.
Thanks
Nik
 
G

Graham Mayor

If the filename has spaces then the spaces must remain in the field.

Forget the merge for a moment.
Does {INCLUDETEXT "J:\\Dept\\staff\\2009\\letter_Page_3.doc"}
or
{INCLUDETEXT "J:\\Dept\\staff\\2009\\letter Page 3.doc"}
insert the document?

If it does not, check the path and filename are correct.

Once you have the insertion working, you can add the field to your merge
document

{IF {MERGEFIELD course} = "Course D" "{INCLUDETEXT
"J:\\Dept\\staff\\2009\\letter_Page_3.doc"}" ""}

Note that in the above which I have pasted from your question, you have
smart quotes around Course D. You need to change those for straight quotes
thus

{IF {MERGEFIELD course} = "Course D" "{INCLUDETEXT
"J:\\Dept\\staff\\2009\\letter_Page_3.doc"}" ""}

Your next page break needs to go inside the quotes around the Includetext
field

"HERE{INCLUDETEXT "J:\\Dept\\staff\\2009\\letter_Page_3.doc"}OR HERE" ""}

You may also need to merge to a new document and update the fields in that
new document in order to display the inserted document.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top