View Single Post
  #19   Report Post  
Posted to microsoft.public.word.mailmerge.fields
macropod[_2_] macropod[_2_] is offline
external usenet poster
 
Posts: 2,059
Default Mergefields, IF statements and section breaks

Hi RoboNix,

The field:
{INCLUDETEXT "C:\\My Documents\\Animals\\{MERGEFIELD ANIMAL}.doc" Layout}
Is only meant to modify the page layout of the target document. To get the rest of the source document, you also need a field coded
as:
{INCLUDETEXT "C:\\My Documents\\Animals\\{MERGEFIELD ANIMAL}.doc"}

--
Cheers
macropod
[MVP - Microsoft Word]


"RoboNix" wrote in message ...
Hello,

I've been following this thread with some interest; it appears I'm
attempting to do almost the exact same thing as JAnderson. Similarly, I'm
having difficulty getting the margins of the target document to adjust to
those of the source document upon merging.

If I'm following this correctly, my target document contains the following
link:

{INCLUDETEXT "C:\\My Documents\\Animals\\{MERGEFIELD ANIMAL}.doc" Layout}

and I've created a bookmark in a section break in the source document called
"Layout". My difficulty is when the merge is completed, I'm getting the
header and footer from the source document, but none of the body of the text.

The only section break I have in the source document is a continuous one at
the end of the document; this is the one I've bookmarked. Any insight as to
why I might only be getting the header and footer? The good news is the
margins appear to be correct in the target document!

This thread has been wonderful in providing insight into a subject that has
repeatedly caused me considerable confusion; many thanks to both of you for
your posts.

"macropod" wrote:

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" wrote in message ...
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" wrote:

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]


"JAnderson" wrote in message ...
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,

"macropod" wrote:

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]


"macropod" wrote in message ...
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]


"JAnderson" wrote in message
...
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,


"macropod" wrote:

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]


"JAnderson" wrote in message
...
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?

"macropod" wrote:

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]


"JAnderson" wrote in message
...
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,


"Graham Mayor" wrote:

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
Word MVP web site http://word.mvps.org



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,

"macropod" wrote:

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]


"JAnderson" wrote in message
news 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