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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ActiveDocument.mailmerge syntax not working

Status
Not open for further replies.

DonS100

Programmer
Dec 4, 2001
104
US
Hello, I'm using this code below from within Access to open a Word document. It works fine on my machine but I have a user that gets an error when trying to run the mailmerge.execute line. Any thought why?

Thanks

Don

Dim objApp As Object
Dim strDocName As String
Dim strDocNameB As String
'strDocName = rs!ClosingDir & "\MasterTest.doc"
strDocName = rs!ClosingDir & "\" & rs!ClosingDoc
Set objApp = CreateObject("Word.application")
With objApp
.Visible = True
.Documents.Open strDocName
strDocNameB = objApp.ActiveDocument.Name
***Lines Below sometimes don't work on other machines.
.ActiveDocument.mailmerge.Destination =0 'wdSendToNewDocument
.ActiveDocument.mailmerge.Execute
.Documents(strDocNameB).Close 0
End With
 
Has Word been opening up showing just a dark grey blank area instead of your document?
 
No, the main document(MailMerge document) opens fine with the data from the linked text file showing correctly. I just get the error when trying to do the mailmerge into a new document, so the new document doesn't open.
 
How about something like:

Code:
Set oApp = CreateObject("Word.Application")

Set oWord = oApp.Documents.Open(FileName:="C:\File.doc")
    
oApp.Visible = True

If ActiveDocument.MailMerge.State = wdMainAndDataSource Then

ActiveDocument.MailMerge.Execute

End If
 
The "Dim's":

Code:
Dim oapp As Word.Application
Dim oword As Word.Document

You may need this inside the If/Then, too:

Code:
ActiveDocument.MailMerge.OpenDataSource "Path&FileName", , , 0, -1, , , , , , , , "", "", 0
 
Shameless self-promotion:

'Native' mailmerge reports - as painless as possible faq181-5088
 
Thanks for the help, this is an issue when using Word 2003.
Seems like the security on Word 2003 drops the linked datasource when opened so I did have to reset the datasource to the text file I use.

ActiveDocument.MailMerge.OpenDataSource "Path&FileName"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top