Results 1 to 9 of 9
  1. #1
    Star Lounger
    Join Date
    Apr 2005
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Insert a SubDocument Based on Field from a Merge (Office 2003, Win XP)

    OK...I've got a rather large mail merge document that (ideally) will get it's field info. from an Access table (populated by a form). Within the document, I want (exactly) 1 of 14 subdocuments inserted (there is one document for each local county we work with). The document inserted will be based on the county chosen in the form. I'm wondering (A) if this is possible; and ([img]/forums/images/smilies/cool.gif[/img] if so, how and where is the best way to accomplish this. i.e...put code in the document itself, or in the form that populates the table, or possibly in the table somewhere?

    Any help is much appreciated.

    B. Drake

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Insert a SubDocument Based on Field from a Mer

    I'm going to assume you don't mean "subdocument" in the magic sense of "master document" and "subdocument" sometimes used in Word... because I don't know anything about those kinds of subdocuments.

    Word has a field code that will import the text of another Word document, INCLUDETEXT. I don't know how much formatting is preserved vs. lost, so you'll have to experiment with it and see whether it meets your needs. Try this: use Insert>Field to insert an INCLUDETEXT field pointing to the first of your 14 documents. Close the dialog. Does it look okay? Press Alt+F9 to show field codes. Then select the file name and path and delete it and use the merge toolbar to insert your mergefield (the one that will contain the complete path to the document) in its place. Press Alt+F9 to return to the normal view of your document. In theory ( <img src=/S/grin.gif border=0 alt=grin width=15 height=15> ), after the merge, the desired document will be right there (where, presumably, there is nothing at the moment).

    Hope this helps.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Insert a SubDocument Based on Field from a Merge (Office 2003, Win XP)

    You must include the filename of the subdocument in the table or query that acts as data source for the mail merge. You can then combine an INCLUDETEXT field and a nested MERGEFIELD field in your Word document, e.g.

    { INCLUDETEXT "C:WordDocuments{ MERGEFIELD Filename }" }

    where C:WordDocuments is the folder containing the documents (note the double backslashes) and Filename is the field in the data source. You should NOT type the field brackets { } yourself.

  4. #4
    Star Lounger
    Join Date
    Apr 2005
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Insert a SubDocument Based on Field from a Merge (Office 2003, Win XP)

    Where abouts should I include the filename(s) of the subdocument(s) in the table that is my data source? Also, I assume I would need to include all of the potential subdocuments in the table as well. Now, is there a way to base which subdocument it includes on one of the fields entered by the user? Example: The user, among other things, say enters 'Dallas' under the County field. The subdocument I would want the program to include in that case would be Dallas_County.doc.
    Any way that is possible?

    Thanks again, guru of Microsoft

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Insert a SubDocument Based on Field from a Merge (Office 2003, Win XP)

    I would use a calculated field in a query based on your table. The field would look like this:

    Filename: [County] & "_County.doc"

    and then use the nested INCLUDETEXT and MERGEFIELD fields in the Word document. This assumes that all subdocuments will be stored in the same folder. If they are stored in different folders, you will need to include the path in the Filename field.

  6. #6
    Star Lounger
    Join Date
    Apr 2005
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Insert a SubDocument Based on Field from a Merge (Office 2003, Win XP)

    You guys are awesome as always! OK...I created a calculated field in the query my merge is now based on called "FileName" (per your last helpful response). Here is the line I've inserted in the Field Codes space of the field I want the fiel to import to. So far, I get Error! Not a vaild filename.

    INCLUDETEXT "Pe2850SharefilesSWPPPEndangered SpeciesMERGEFIELD FileName"

    This is a server, if that makes a difference.

    Thanks, as always, you're the main man to turn to for all MS Office woes.

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Insert a SubDocument Based on Field from a Merge (Office 2003, Win XP)

    It looks as if you haven't really inserted a MERGEFIELD field. Select the text [/b]MERGEFIELD FileName[/b] and press Ctrl+F9 to turn it into a field, then press F9 to toggle the field code.

  8. #8
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Insert a SubDocument Based on Field from a Merge (Office 2003, Win XP)

    Hi reverendleo,

    Since you're getting the filename from a FORMFIELD, your INCLUDETEXT field won't be calling a MERGEFIELD at all. Instead, it'll be calling the FORMFIELD's bookmark which, I understand from your post, is 'FileName'. Your field is also missing the drive designation, which I think you'll also find is needed. Taking both issues into account, and assuming the folder is on drive C, the correct coding for the field varies a bit, depending on whether 'FileName' includes the '.doc' extension. If the '.doc' extension is:
    . part of the 'FileName' bookmark, the correct coding would be -
    {INCLUDETEXT "C:Pe2850SharefilesSWPPPEndangered Species{FileName}"}
    . not part of the 'FileName' bookmark, the correct coding would be -
    {INCLUDETEXT "C:Pe2850SharefilesSWPPPEndangered Species{FileName}.doc"}
    When inserting the 'FileName' bookmark reference into the INCLUDETEXT field it is essential that the field braces enclosing it (i.e. '{}') are created via Ctrl-F9 - using standard text for these won't work.

    Cheers
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  9. #9
    Star Lounger
    Join Date
    Apr 2005
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Insert a SubDocument Based on Field from a Merge (Office 2003, Win XP)

    Thanks for the tip! I actually got the form to work with the INCLUDETEXT and a nested MERGEFIELD.
    My initial problem was that I was trying to nest the MERGEFIELD in the field codes section of the original INCLUDETEXT field. It didn't like that.
    However, when I selected 'Toggle Field Codes', and selected the INCLUDETEXT field, I was able to highlight 'MERGEFIELD FileName' and use the old
    CTRL-F9, and, boom! Success! You guys are all the best, thanks for all the help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •