none
MergeFields / FormFields - Can both be defined ? RRS feed

  • Question

  • I have a complex requirement to merge data to a word document and then have it converted to a PDF file.
    With mergefields, this has been working fine.

    However, the problem has always been : the client would prefer to have that merged data modifiable in the PDF document in the way of PDF form fields. 

    Is it possible to have the fields merged with the data and then redefine them as form fields so they are translated as such when converted to a PDF ?

    Saturday, June 29, 2013 7:58 PM

Answers

  • Once a mail merge has completed, no trace whatsoever of the mail merge fields remains - only the result. So you don't know where the mail merge fields were.

    Text form fields don't survive a mail merge (dropdown form fields and check box form fields do).

    I think you'd have to write your own merge-like routine to obtain the result that you want.


    Regards, Hans Vogelaar

    Sunday, June 30, 2013 3:28 PM
  • Text form fields don't survive a mail merge (dropdown form fields and check box form fields do).

    Hans, isn't that somewhat of a bug ? Why would one type survive and the other be removed ?

    It's actually by design and is NOT a bug. Field codes, generally, are turned into static text during a mail merge - that's how mail merge was designed to function. Bookmarks will also be removed during mail merge as you can't have duplicate bookmark names in a document. Form fields are field codes AND they're bookmarks. Also, Mail merge can't be performed on a document protected as a form; in order to run mail merge, forms protection needs to be removed, so it's not "logical" that the user would try to use mail merge with a form.

    Yes, I know, many people (would like to) do it, but Word wasnt' designed to work that way. There's a KB article on the topic with some "workaround" code, if that helps at all: http://support.microsoft.com/?kbid=211308


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, July 4, 2013 2:10 PM
    Moderator

All replies

  • Once a mail merge has completed, no trace whatsoever of the mail merge fields remains - only the result. So you don't know where the mail merge fields were.

    Text form fields don't survive a mail merge (dropdown form fields and check box form fields do).

    I think you'd have to write your own merge-like routine to obtain the result that you want.


    Regards, Hans Vogelaar

    Sunday, June 30, 2013 3:28 PM
  • I was afraid of that. I was wondering if I could use bookmarks in some way to mark these fields ? 

    Then I thought I could convert them to form fields using VBA. Hopefully, they would convert to PDF form fields after the conversion.

    Another option I am considering is doing the merge directly to a PDF file that would have the form fields already defined....thus bypassing the word-to-pdf file conversion. This option would probably require some javascript on the PDF side as well as the use of the Acrobat COM library with VBA.

    Sunday, June 30, 2013 4:31 PM
  • My suggestion would be that you set up the base document with form fields, rather than merge fields. You can use object model automation (VBA, for example) or you can leverage the Open XML SDK to "merge" the data into the form fields. (Your code would need to write each data item to the target field, rather than perform a MailMerge.Execute.)

    Or, you can go the way you describe, generating a PDF file directly from the data. But any discussion along those lines would be outside the scope of this forum as it would not involve Word or its object model (Word doesn't provide any support for going directly to PDF).


    Cindy Meister, VSTO/Word MVP, my blog

    Sunday, June 30, 2013 5:47 PM
    Moderator
  • Thanks Cindy. This is a tough call. The main reason being that even if the Adobe PDF converter did a good job of translating Word form fields to PDF form fields, I still must add a ton of Javascript code to the merged PDF to perform validation.

    However, I do love the reliability of the MailMerge facility in Word. Alas, I cannot rely upon it because the document with the form fields must go out to clients, each with different versions of Word ! Coding and testing multiple versions is extremely time-consuming and expensive. The PDF reader can be downloaded for free and we can standardize on the exact release if need be.

    So this appears to be making a case for doing a VBA-driven database fields to PDF form fields approach.

    Tuesday, July 2, 2013 11:23 PM
  • Text form fields don't survive a mail merge (dropdown form fields and check box form fields do).

    Regards, Hans Vogelaar


    Hans, isn't that somewhat of a bug ? Why would one type survive and the other be removed ?
    Thursday, July 4, 2013 1:28 AM
  • It may be a bug but it has been present at least since Word 97. It has been documented by Microsoft but not fixed, so the probability that it will ever be changed is minimal.

    Regards, Hans Vogelaar

    Thursday, July 4, 2013 4:26 AM
  • Text form fields don't survive a mail merge (dropdown form fields and check box form fields do).

    Hans, isn't that somewhat of a bug ? Why would one type survive and the other be removed ?

    It's actually by design and is NOT a bug. Field codes, generally, are turned into static text during a mail merge - that's how mail merge was designed to function. Bookmarks will also be removed during mail merge as you can't have duplicate bookmark names in a document. Form fields are field codes AND they're bookmarks. Also, Mail merge can't be performed on a document protected as a form; in order to run mail merge, forms protection needs to be removed, so it's not "logical" that the user would try to use mail merge with a form.

    Yes, I know, many people (would like to) do it, but Word wasnt' designed to work that way. There's a KB article on the topic with some "workaround" code, if that helps at all: http://support.microsoft.com/?kbid=211308


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, July 4, 2013 2:10 PM
    Moderator