Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mail merge

Status
Not open for further replies.

striker73

MIS
Jun 7, 2001
376
US
I am working on a database application that contains a form where a user can specify what customers he wants to send a letter to. There are also other filters on this page (such as a certain industry, a certain zip code, territory, etc.) Right now, I have the form set up so when you click the button, filters are applied when a report is open.

What I want to happen is:

When the cmd button is clicked
'select appropriate entries in Contacts table
'clear Temp table
'copy these new entries to Temp table
'open Word document that is set up for mail merge


How can I do this in VBA? What is the syntax? Thanks!!

 
I haven't figured out how do exactly what I want just yet, but this is what I have figured out so far. You can open a word document using VBA by the following code:

This assumes that the word document is already created. Also you need to set references so that you may access Word documents. (In Visual Basic, Tools --> References. Check the box that says "Microsoft Word 9.0 Object Library")

Dim objWord as Word.Document
Set objWord = GetObject("C:\Location\mydoc.doc", "Word.Document")
objWord.Application.Visible 'Make the document visible
'Set the mail merge data source
objWord.MailMerge.OpenDataSource Name:="C:\Location\mydb.mdb", LinkToSource:=True, Connection:="TABLE Customers" SQLStatement:="SELECT * From [Customers]"
'Execute the mail merge
objWord.MailMerge.Execute

Hope that helps anyone else.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top