MS Office Forum / Word / Mailmerge and Fax / July 2008
Mergefields, IF statements and section breaks
|
|
Thread rating:  |
JAnderson - 16 Jul 2008 17:26 GMT 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 whole document starting with "Bear", then "Zebra", then "Lion", then "Regular document"? Is this just a lost cause?
(The reason I am insistent on doing it this way is because, on a grander scale, I do not want to have hundreds of individual documents to use for merging data; I would prefer to have one 'master' document.)
Thanks in advance,
macropod - 16 Jul 2008 23:08 GMT 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.
 Signature Cheers macropod [MVP - Microsoft Word]
> Ok, this is a somewhat complicated one, so bear with me: > [quoted text clipped - 47 lines] > > Thanks in advance, JAnderson - 16 Jul 2008 23:29 GMT 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, > [quoted text clipped - 59 lines] > > > > Thanks in advance, Graham Mayor - 17 Jul 2008 06:57 GMT 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.
 Signature <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP
My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Hmm... So could I still use conditional statements with INCLUDETEXT? > If my database record is 'zebra', I only want my zebra document to [quoted text clipped - 88 lines] >>> >>> Thanks in advance, JAnderson - 17 Jul 2008 20:37 GMT 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 [quoted text clipped - 93 lines] > >>> > >>> Thanks in advance, macropod - 17 Jul 2008 23:31 GMT 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'.
 Signature Cheers macropod [MVP - Microsoft Word]
> Ah, that makes sense, thank you. It looks like the last of my problems is > formatting. [quoted text clipped - 103 lines] >> >>> >> >>> Thanks in advance, JAnderson - 18 Jul 2008 19:01 GMT 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, > [quoted text clipped - 110 lines] > >> >>> > >> >>> Thanks in advance, macropod - 18 Jul 2008 23:16 GMT 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)?
 Signature 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, [quoted text clipped - 135 lines] >> >> >>> >> >> >>> Thanks in advance, JAnderson - 19 Jul 2008 00:16 GMT 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, > [quoted text clipped - 145 lines] > >> >> >>> > >> >> >>> Thanks in advance, macropod - 19 Jul 2008 09:48 GMT 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.
 Signature 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 [quoted text clipped - 159 lines] >> >> >> >>> >> >> >> >>> Thanks in advance, macropod - 19 Jul 2008 11:40 GMT 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.
 Signature Cheers macropod [MVP - Microsoft Word]
> Hi JAnderson, > [quoted text clipped - 169 lines] >>> >> >> >>> >>> >> >> >>> Thanks in advance, JAnderson - 19 Jul 2008 21:57 GMT 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. [quoted text clipped - 172 lines] > >>> >> >> >>> > >>> >> >> >>> Thanks in advance, macropod - 20 Jul 2008 22:37 GMT 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.
 Signature Cheers macropod [MVP - Microsoft Word]
> Hmm... That seems problematic. Say my target document has 1" margins and no > header/footer. Then, for example: [quoted text clipped - 189 lines] >> >>> >> >> >>> >> >>> >> >> >>> Thanks in advance, JAnderson - 21 Jul 2008 16:36 GMT 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, > [quoted text clipped - 202 lines] > >> >>> >> >> >>> > >> >>> >> >> >>> Thanks in advance, macropod - 21 Jul 2008 22:08 GMT 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 [quoted text clipped - 221 lines] >> >> >>> >> >> >>> >> >> >>> >> >> >>> Thanks in advance, RoboNix - 22 Jul 2008 17:16 GMT 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.
> Hi JAnderson, > [quoted text clipped - 229 lines] > >> >> >>> >> >> >>> 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 macropod - 22 Jul 2008 22:43 GMT 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"}
 Signature Cheers macropod [MVP - Microsoft Word]
> Hello, > [quoted text clipped - 259 lines] >> >> >> >>> >> >> >>> 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 JAnderson - 22 Jul 2008 20:46 GMT 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, > [quoted text clipped - 229 lines] > >> >> >>> >> >> >>> 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 macropod - 22 Jul 2008 22:39 GMT 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. [quoted text clipped - 244 lines] >> >> >> >>> >> >> >>> 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 JAnderson - 23 Jul 2008 01:05 GMT 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, > [quoted text clipped - 225 lines] > >> >> >> >>> >> >> >>> ---section break (next page)--- > >> >> >> >>> >> >> >>> " ""} macropod - 23 Jul 2008 01:16 GMT 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.
 Signature Cheers macropod [MVP - Microsoft Word]
> Yes, perfect- that works. > [quoted text clipped - 272 lines] >> >> >> >> >>> >> >> >>> ---section break (next page)--- >> >> >> >> >>> >> >> >>> " ""} JAnderson - 23 Jul 2008 16:16 GMT 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!
> Hi JAnderson, > [quoted text clipped - 230 lines] > >> >> >> >> >>> >> >> you can put mergefields in the included documents and they will work > >> >> >> >> >>> >> >> provided they match the fields in your data source. macropod - 23 Jul 2008 22:31 GMT 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.
 Signature Cheers macropod [MVP - Microsoft Word]
> 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 [quoted text clipped - 241 lines] >> >> >> >> >> >>> >> >> you can put mergefields in the included documents and they will work >> >> >> >> >> >>> >> >> provided they match the fields in your data source. Stan at Oak Ridge - 24 Jul 2008 14:45 GMT 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
> Hi JAnderson, > [quoted text clipped - 229 lines] > >> >> >>> >> >> >>> 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 macropod - 25 Jul 2008 02:21 GMT 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.
 Signature Cheers macropod [MVP - Microsoft Word]
> 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 [quoted text clipped - 250 lines] >> >> >> >>> >> >> >>> 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 Stan at Oak Ridge - 25 Jul 2008 14:21 GMT 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
> Hi Stan, > [quoted text clipped - 219 lines] > >> >> >> >>> >> >> >>> Document relating to bears > >> >> >> >>> >> >> >>> More text, formatting of 0.5" margins
|
|
|