What library has MailMerge.OpenDataSource?

garlicman

Registered User.
Local time
Today, 00:12
Joined
Jan 13, 2010
Messages
10
I want to click a button and do a mail merge in a Word document. I saw numerous examples of this using MailMerge.OpenDataSource.

One document said that this was in microsoft.office.interop.word.dll. I found Microsoft.Office.Interop.Word in C:\Windows\Assembly, but cannot include it from Tools > References > Browse.

When I try to run my code I receive this Visual Basic message:
Compile error:
Method or data member not found.

MailMerge is highlighted in my code, so I am certain that's where the problem lies.

One document I read made me think that I should add Microsoft DAO 3.6 Object Library. However, when I tried to include it, I received the following Visual Basic message:

Name conflicts with eisting module,project, or object library. I can't find any conflicts with the existing references:

Visual Basic For Applications
Microsoft Access 12.0 Object Library
OLE Automation
Microsoft ActiveX Data Objects 2.1 LIbrary
Microsoft Office 12.0 Access database engine Object Library
 
If word is properly installed then in the reference list select by checking the:

Microsoft Word 12.0 Object Library
 
Hmm. I have the Microsoft Word 12.0 Object Library included. How do I verify that Word is "installed properly"? Word seems to be working without any problems.

I have Microsoft Office 2007 on Windows XP Professional with SP3.
 
The samples that I saw all use objWord.MailMerge.OpenDataSource.

I found objWord.MergeDocuments.MailMerge.OpenDataSource. Is this the same thing? How can I account for the difference that the samples have? Yes, this is with Microsoft Word 12.0 Object Library.
 
You will need to be sure that you use all the code from the example and not just a single line. You must make sure taht you create all the same objects in the same way.

Can you post ALL the code from the example and ALL your VBA code for this routine?
 
This is the code I borrowed. I made these changes:
- The paths and file names for the .doc and .mdb files
- objWord.MailMerge.OpenDataSource isn't available for some reason. Yes, I included a reference to Microsoft Word 12.0 Object Library. Instead I used objWord.MergeDocuments.MailMerge.OpenDataSource. I don't know how significant this change might be.

Code:
Dim objWord As Word.Application
 
Set objWord = GetObject("C:\Documents and Settings\jketcher\My Documents\Janis 
Folder November 6\ECG\MS Access Projects\ECGOpReview", _
"Word.Document")
 
'Make Word visible.
objWord.Application.Visible = True
 
'Set the mail merge data source as
objWord.MailMerge.OpenDataSource _
Name:="C:\Program Files\Microsoft Office\Office12\OpReviewDBV8TestReport.mdb", _
LinkToSource:=True, _
Connection:="TABLE tblMergeFindings", _
SQLStatement:="SELECT * FROM [tblMergeFindings]"
 
'Execute the mail merge
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute
 
Instead I used objWord.MergeDocuments.MailMerge.OpenDataSource. I don't know how significant this change might be.

Have you tried it the way it using the original code (the objWord.MailMerge.OpenDataSource... ) ?
 
Yes, I tried using objWord.MailMerge.OpenDataSource from the original sample, and that resulted in the "method or data member not found" error. I used a slightly different example that also uses objWord.MailMerge.OpenDataSource, and it worked for me, so I'm sticking with that.

Thanks much for your assistance.
 

Users who are viewing this thread

Back
Top Bottom