Results 1 to 2 of 2
  1. #1
    Join Date
    May 2004

    Unanswered: Mailmerge code from Access to Word

    I need to do a mailmerge from access to a word document.
    The code will be run from a form..

    so basically I have a table name "CLIENTS" ordered by FileNumber

    and a form name "ENTRYFORM"

    I want to merge the client's information into a document by their FileNumber

    I also have a field lastname
    After merging, I want to save the file as the last name of the client

    Does anyone have any idea?

  2. #2
    Join Date
    Nov 2003
    Try something like this.....

    Dim objWord As Word.Document
    Set objWord = GetObject(DatabasePath & "myDocument.doc", "Word.Document")
    objWord.Application.Visible = True
    objWord.MailMerge.OpenDataSource Name:=DatabasePath & "myDatabaseName.mdb", LinkToSource:=True, Connection:="TABLE myTableName", SQLStatement:="SELECT * FROM [myTableName] WHERE [myTableFieldName] = " & Me!myFormFieldName
    objWord.Application.Documents(2).Close wdDoNotSaveChanges
    DoCmd.Hourglass False
    Set objWord = Nothing
    Set objDoc = Nothing
    Where DatabasePath is the Path to your database (MDB) file.

    You can create the myDocument.Doc by using;

    DoCmd.OutputTo acOutputReport, "myNameOfdatabaseReport", acFormatRTF, DatabasePath & "myDocument.Doc"

Posting Permissions

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