Word Merge For Form Letter Code Error

C

Craig

The below code has worked for many years until my client got a new machine.:
Dim myWord As Word.Application
Dim myDoc As Word.Document
Dim sFileName As String
Dim sPath As String

sPath = CurrentProject.Path
sFileName = "\ThankYou.doc"
sFileName = sPath & sFileName

Set myWord = New Word.Application
Set myDoc = New Word.Document

myWord.Visible = True
Set myDoc = myWord.Documents.Open(sFileName)

With myDoc.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
myDoc.Close

All of the code references for Word 11.0 are checked. I now get the error
message "Requested Object is not available."

Any help appreciated:)
 
D

Douglas J. Steele

Try removing the line

Set myDoc = New Word.Document

It's really redundant, since you're setting myDoc two lines later.
 
C

Craig

Checking for the Word 11.0 Object Library was the first thing I did. It's
there and the app compiles. Word does appear with the form letter but w/o the
merged data from Access.
 
C

Craig

Ooppps..I still get the error message. I compile the app to verify that all
of the references are set.
 
D

Douglas J. Steele

C

Craig

I originally wrote the code back in 2001 using Access 2000. I notice from
that CindyMeister article that the coding has changed. So I will try to
update my code from what she has listed. Thanks for the help Doug!:)
 
P

Pete D.

What did you find, did it fix it? Please share, I want to
learnnnnnnnnnnnnnnn. Okay, stop laughing I really can be taught! Pete D
 

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