Late Binding -- Member Not Found

G

Guest

Hello,

I posted a previous question that asked about 2 different word references
being used in an access database. I guess there is a problem and I was
advised to try late binding vs early binding. I thought I rewrote the code
correctly, but I am getting a Data member not found error on the .mailmerge
action. Could someone look at the code below and perhaps see what I might
have done wrong?
Rick,

I tried using the late binding, but I received an error that said data
member not found. Perhaps if you look at this code you might be able to tell
me what I did wrong. Thanks, D.

Dim objWord As Object
Dim objDoc As Document

Set objWord = CreateObject("Word.Application")
objWord.Application.Visible = True

Set objDoc = objWord.Documents.Open(strDir & strDocumentName)
objdoc.MailMerge.OpenDataSource _
Name:="C:\Documents and Settings\D\Desktop\Projects\Project
Tracking.mdb", _
LinkToSource:=True, AddToRecentFiles:=False, _
Connection:="QUERY qselVendorNames", _
SQLStatement:=strSQL

P.S. I have defined strDir and strDocumentName

Thanks,
D.
 
B

Brendan Reynolds

You're still declaring objDoc "As Document". As you no longer have a
reference to the Word object library, this is being interpreted as a
reference to the DAO Document object, which does not have a MailMerge
property.

You need to declare objDoc as "As Object" instead.
 
G

Guest

Hello,

Can I now remove the reference to the Word Library, or does that still stay?
I tried removing it and it did not recognize these lines of code:

objDoc.MailMerge.Destination = wdSendToNewDocument
objDoc.MailMerge.Execute
objWord.Application.Documents(2).Close wdDoNotSaveChanges

It thought that wdSendToNewDocument was an undeclared variable.

Thanks,
D.
 
D

Douglas J Steele

The reference to the Word library should be removed.

I wouldn't expect it to have a problem with objDoc.MailMerge.Execute, but
the reason it's failing on the other two lines is because it doesn't know
the values of the constants wdSendToNewDocument and wdDoNotSaveChanges.
Turns out both of those constants are equal to 0, so replace them with 0 (or
assign them values in code)
 
B

Brendan Reynolds

Yes, you need to remove the reference to the Word object library. Before you
do that, though, look through your code and make a note of all of those
"wdSomething" constants. You need to determine the value of those constants,
which you can do either by placing the insertion point in the name of the
constant and pressing Shift+F2 to go to the definition of the constant in
the Object Browser, or by printing the value of the constant in the
Immediate window, e.g. ? wdSendToNewDocument. Both of these techniques for
determining the value depend on the reference to the Word object library, so
it's worth finding them before you remove the reference.

When you've made a note of the name and value of each Word constant that
you're using, you can remove the Word reference and then declare your own
constants with the same values, and use those constants in your code in
place of the Word constants. For example ...

Public Const dcSendToNewDocument As Long = 0
Public Const dcDoNotSaveChanges As Long = 0

objDoc.MailMerge.Destination = dcSendToNewDocument
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top