Share via

Automatic mailmerge from Access table

Anonymous
2024-08-01T09:47:52+00:00

Hi,

I have created a Word document which has a connection to a database table with all fields defined in the document.

I have tried various ways to get Access VBA to open the document, automatically populate the data and save the Word document as a PDF file.

Does anyone have any code I could try please?

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

6 answers

Sort by: Most helpful
  1. ScottGem 68,830 Reputation points Volunteer Moderator
    2024-08-01T19:32:55+00:00

    May still be done as a report.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2024-08-01T16:39:55+00:00

    You might like to take a look at AccWord.zip in my public databases folder at:

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

    This little demo file illustrates a number of Access to Word automation operations.  For merging the method used is to export the result table of a query to a delimited text file, which is then used as the source document for the merge.

    If you are creating a single document, rather than merging a set of records to a set of word documents, you might like to consider inserting text at bookmarks in the Word template file.  This is also illustrated in my demo.

    The demo does not including saving a document as a PDF, but if you were to do as Scott suggests, and, rather than using Word, create an Access report, this becomes simple.  The InvoicePDF.zip demo in my same OneDrive folder illustrates how to do this.  If you do use Word, my AccWord demo does not include this, but I've just recorded the following VBA procedure, called a 'macro' in word, for doing so with a Word document of one of the invoices created by the InvoicePDF demo.  This could be easily incorporated into my AccWord demo by passing the paths to the folder and file into the procedure as arguments, rather than hard coding them in the procedure:

    Sub SaveAsPDF()

        ActiveDocument.ExportAsFixedFormat OutputFileName:= _

            "C:\Users\kenws\Documents\Databases\InvoicePDF\ACME Flange Company\ACME Flange Company 20111208103010.pdf" _

            , ExportFormat:=wdExportFormatPDF, OpenAfterExport:=True, OptimizeFor:= _

            wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _

            Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _

            CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _

            BitmapMissingFonts:=True, UseISO19005_1:=False

        ChangeFileOpenDirectory _

            "C:\Users\kenws\Documents\Databases\InvoicePDF\ACME Flange Company"

    End Sub

    Was this answer helpful?

    0 comments No comments
  3. DBG 11,711 Reputation points Volunteer Moderator
    2024-08-01T15:45:00+00:00

    Hi,

    I have created a Word document which has a connection to a database table with all fields defined in the document.

    I have tried various ways to get Access VBA to open the document, automatically populate the data and save the Word document as a PDF file.

    Does anyone have any code I could try please?

    Go to this link and search for "Super Easy Word Merge."

    http://kallal.ca/msaccess/msaccess.html

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2024-08-01T14:09:57+00:00

    Hi Scott,

    it is a fairly complicated 5 page application form.

    Was this answer helpful?

    0 comments No comments
  5. ScottGem 68,830 Reputation points Volunteer Moderator
    2024-08-01T12:27:23+00:00

    Have you tried creating your form letter as an Access report?

    Was this answer helpful?

    0 comments No comments