Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2003

    Unhappy Unanswered: Exporting to Word for mail merge - almost there? Please help!

    Currently I have a form where I filter the records based on the selection of combo boxes. I want now to use the filtered records as data source for Word to merge. I know many of you have done it successfully. I am almost there too, but need a bit of help.

    Here is the code behind the OnClick event of a button on the same form where I filter the records.
    Private Sub MergeButton_Click()

    Dim objWord As Word.Document
    Dim db As DAO.Database
    Dim qrMain As QueryDef
    Dim sqlSearchFor As String 'to filter further the query

    Set db = CurrentDb
    Set qrMain = db.QueryDefs("WhoTook")

    sqlSearchFor = Me.RecordSource

    Set objWord = GetObject("C:\Jobs\Massage Academy\HS-MergeLetter.doc", "Word.Document")

    objWord.Application.Visible = True

    objWord.MailMerge.OpenDataSource _
    Name:="C:\JOBS\Massage Academy\HS-Installed-May17-04.mdb", _
    LinkToSource:=True, _
    Connection:="QUERY qrMain", _

    objWord.MailMerge.Destination = wdSendToNewDocument


    End Sub

    This will run and open Word and the Document for merging only.

    I will also open another instance of Access, which I do not want!!! Access is already open, since I start the merging process from a form.

    And it will generate an run time err: - Word was not able to open the data source.

    Just to clarify - the data source for the merging must be the same as it is for the Form, and I use a sql string to filter the main query for the form. Perhaps I fail to properly point Word to that data source.

    Instead of using
    objWord.MailMerge.OpenDataSource --- this opens another db instance
    can I use
    objWord.MailMerge.DataSource? And if so, pls provide an example.


    Last edited by jazz novice; 09-06-04 at 19:28.

  2. #2
    Join Date
    May 2004
    South Australia

    Similar Problem

    Hi Jazz,

    Did you ever get this working? I am experiencing problems with the Word mail merge myself, although my knowledge of code is not as great.
    Basically I have tried to use the mail merge function from Word, but it only presents me with a list of my tables and 2 queries - despite the fact that I have 15 or so. Also, the mail merge button that Access provides for reports is simply greyed out.

    My suspicion is that you cannon mail merge with a parameter query, but I would have though it should at least work whilst the database is running.

    I am no longer working on this database, but if you or someone else has the time I would be interested in learning of a solution.


Posting Permissions

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