Share via

Mailmerge a Word document and save as a PDF

Anonymous
2024-07-26T06:45:36+00:00

Hi,

I am running Word and Access 2016 on a Windows 11 laptop.

I have created a mailmerge Word document which I want to populate data from an Access database query and then save the Word document as a PDF so that the routine can then email it to a customer.

Does anyone have any VBA code that is close to what I am trying to do please?

Just to elaborate a bit more.....

my query retrieves about 80 records.

I want to be able to have a loop which loops round each record, opens a word document which has the mail merge in, automatically runs the mailmerge, converts the document to a pdf and then emails the pdf to a customer, then loop round for the next record until eof.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

  1. Doug Robbins - MVP - Office Apps and Services 322.9K Reputation points MVP Volunteer Moderator
    2024-07-26T23:08:19+00:00

    Use my Merge Tools Add-in that is contained in the MERGE TOOLS ADD-IN.zip file that you can download from:

     https://mergetoolsaddin.com/

    Extract the files from the archive and read the:

    “READ ME – Setting up and using the Merge Tools Add-in.pdf

    to see how to install and use the various tools.

    Using those tools, it is possible to perform the following types of merge that cannot be done with Mail Merge “out-of-the-box”:

    • Merge to e-mail messages either with or without attachments, with the documents created by the merge being sent as either Word or PDF attachments or as the body of the e-mail message .  The email messages can, if necessary, also be sent to CC and BCC addresses and the subject of the message can include data from a field in the data source.
    • Merge to individual documents in either Word or PDF format with the filenames being supplied by the data in one of the fields in the data source
    • Many to One type merges, which can be used for creating documents such as invoices where there are multiple records in the data source that have common data in one of the fields
    • Merging to a document that will include a chart that is unique to each record in the data source
    • Merging a document with Content Controls
    • Merging a document that contains Legacy FormFields
    • Duplex Merges
    • Merging to a printer that will collate and staple the output created from each record in the data source.

    The requirements for using the system are:

    • The mail merge main document must be of the Letters type, though that does not mean that the output cannot be sent as an e-mail message where relevant.
    • For the Many To One, Merge with Attachments and Merge to Individual Docs utilities, the data source may be either a table or query in an Access database, or in the form of an Excel worksheet. For the Chart Merge utility, see the Mail Merging with Charts document that is included in the Merge Tools Add-in Zip file for additional requirements for the data source for use with that utility
    • For a data source in the form of an Excel worksheet, the field names must be in the first row of the worksheet and there must be a field name in all of the cells in that row that are within the range of columns that contain the data.
    • For both types of data source, the field names must contain only alphanumeric characters (No @,#,$,%,&,(,), etc) and the field names must not start with a numeric character (0-9). The number of characters in the field names, including spaces, must not be more than 40.

    The MergeTools Add-in will NOT work with the “New Outlook”, which is just a re-badged version of Windows Mail and like its predecessor, it does not support automation and hence will not send the messages created by the MergeTools Add-in.

    Be aware, that any messages that you had tried to send with the “New Outlook” will have been placed in the Outbox of the original Outlook and they will be sent as soon as you revert to that version of Outlook.   If you do not want that to happen, you should put Outlook Off-line, or disconnect your computer from the Internet.

    1 person found this answer helpful.
    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Anonymous
    2024-07-27T07:18:40+00:00

    Hi Doug,

    your download won't download as it says it has a virus.

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2024-07-26T22:14:08+00:00

    I'd agree with Scott that outputting the forms as Access reports as PDF attachments to the emails would be a simpler solution.  You might like to take a look at InvoicePDF.zip in my public databases folder at:

    https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169

    This little demo file includes an option for emailing multiple reports to one or more customers.  The demo allows for multiple invoices to be mailed to each customer, but the same methodology could be used to mail one invoice per customer.

    0 comments No comments
  3. Anonymous
    2024-07-26T10:15:38+00:00

    Hi,

    The form is a fairly complicated form for recording membership applications.

    I want to populate the form and email it to each member to check their details are still correct...

    0 comments No comments
  4. ScottGem 68,810 Reputation points Volunteer Moderator
    2024-07-26T09:55:04+00:00

    What does your Word document look like? I have found that using a Word mail merge is often problematic. I've had much better success with creating an Access report that mimics a form letter. This is especially true when the Access data includes multiple rows.

    The code for generating a report and e-mailing it within Access is easy and commonly available. To do it with a mail merge requires Office Automation to Open Word and save the Word file as a PDF, then run Access code to amil it with an attachment.

    0 comments No comments