Word MailMerge from Access

Local time
Today, 14:59
Joined
Aug 7, 2008
Messages
1
I'm looking for a way to launch word, open a document and do a mail merge to the document from a query in Access from the click of a single button on a form. Is there an easy way to do this?

I can successfully populate the document if doing it from word but when I attempt it from access, it cuts off about 2/3's of my columns and throws an error to the effect that it can't find the columns defined on the mail merge document. Unfortunately, I have about 200 columns on the table that the query populates from.

I'm using Access 2002, Vista.
 
Yes you can do this, but I would caution doing this in word. You will need to run make table queries and then Word will be able to see these tables. Word will also lock these tables so if there are more than one users, they will get an error if they try to open the same Word document. I have gotten around this issue by have the query export the data to a CSV file. Then in my code I tell Word to find the data. I am currently having an issue with some of the Word Documents.

Here is my post you can see the code I use to first create a folder for which loan the user selects and then I have all my queries run to export to CSV files into that folder.

I then look to see which loan was selected and then I open word tell it what document to open and where the data is located.

Here is my post with the code.
http://www.access-programmers.co.uk/forums/showthread.php?t=154526
 
try the super easy word function -
this words from a table - but you could do a make table qry andthen run the mail merge from this -
it really is easy

notes on this
(1) find it on the samples or from google..

(2) it words from a table and a form based on the table (you can make the fields not visible - but add them to the form

(3) formatting of numbers may get lost - you might need to look at switches in word for formatting of numbers -

hoep this helps
 
I put the following code on a button click and it runs a mail merge (usually of about 5000 records) just fine. Basically, click the button and the merge will fire no problem. Upon completion, both the mail merge, the template, AND the database will close! Ofcourse, you could make the necessary edits to change that. Hope that can be of some use for you!


Code:
Private Sub Command3_Click()

On Error GoTo Click_Err

   Dim objWord As Word.Document
     Set objWord = GetObject("'Path to Word Mail Merge Template", "Word.Document")
     ' Make Word visible.
   objWord.Application.Visible = True
   ' Set the mail merge data source as the Mailmerge database.
   objWord.MailMerge.OpenDataSource _
      Name:="'path to DB", _
      LinkToSource:=True, _
      Connection:="TABLE SelectedRecords", _
      SQLStatement:="SELECT * FROM ['table name]"
   ' Execute the mail merge.
      objWord.MailMerge.Destination = wdSendToNewDocument
      objWord.MailMerge.Execute
    ' Below saves and closes new doc
    objWord.Application.Options.SaveInterval = False
    objWord.Application.ActiveDocument.SaveAs "'insert file name here"
    objWord.Application.ActiveDocument.Close
    objWord.Application.Quit wdDoNotSaveChanges
    
    MsgBox "Mail Merge Complete!", vbOKOnly, "File Done"
  
  DoCmd.Quit
  
Click_Exit:
    Exit Sub

Click_Err:
    MsgBox Error$
    Resume Click_Exit
  End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom