To run several Word mail merges from Access

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • damezumari

    #1

    To run several Word mail merges from Access

    I use MS Office 2003 and would like to run several Word mail merges
    from Access.

    My code so far is given below.

    1. The code does not do what I want. I want to save the new document
    with the merge result, not the merge template I start out with. At the
    moment it saves the latter.

    2. I would like all Word documents to be closed in the end.

    3. I would like to run several queries and for each of them do a mail
    merge to a new document that is being saved.

    Any help with 1-3 would be most welcome.

    Regards,

    Jan Nordgreen

    ---

    Option Compare Database

    'References: Microsoft Word 11 Object Library

    Private Sub Command0_Click( )

    ' variables
    Dim folder As String
    folder = "G:\GIS\sch ool administration\ reports\"
    Dim template As String
    template = "report template.doc"
    Dim database As String
    database = "create report documents.mdb"
    Dim objWord As Word.Document
    Set objWord = GetObject(folde r & template, "Word.Document" )

    ' Make Word visible.
    objWord.Applica tion.Visible = True
    objWord.MailMer ge.OpenDataSour ce _
    Name:=folder & database, _
    LinkToSource:=T rue, _
    Connection:="TA BLE Test", _
    SQLStatement:=" SELECT * FROM [Test]"

    ' Execute the mail merge.
    objWord.MailMer ge.Destination = wdSendToNewDocu ment
    objWord.MailMer ge.Execute

    ' Save the document
    objWord.SaveAs FileName:=folde r & "7.doc",
    FileFormat:=wdF ormatDocument, _
    LockComments:=F alse, Password:="", AddToRecentFile s:=True,
    WritePassword _
    :="", ReadOnlyRecomme nded:=False, EmbedTrueTypeFo nts:=False, _
    SaveNativePictu reFormat:=False , SaveFormsData:= False,
    SaveAsAOCELette r:= _
    False

    ' Release the object variable.
    objWord.Close
    Set objWord = Nothing

    End Sub
  • Tony Toews [MVP]

    #2
    Re: To run several Word mail merges from Access

    damezumari <jannordgreen@g mail.comwrote:
    >I use MS Office 2003 and would like to run several Word mail merges
    >from Access.
    >
    >My code so far is given below.
    See Albert Kallal's Super Easy Word Merge - Scroll down a ways


    No code required on your part as his tool as all the code needed.

    Tony
    --
    Tony Toews, Microsoft Access MVP
    Please respond only in the newsgroups so that others can
    read the entire thread of messages.
    Microsoft Access Links, Hints, Tips & Accounting Systems at

    Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/

    Comment

    Working...