Hi,
Im trying to launch a mail Word merge from Access 2007. Everything works fine first time around, but on a second attempt to run the mail merge I get a runtime error 462 - the remote server machine does not exist or is unavailable. I think this is something to do with VBA not releasing Word but I can’t get a fix. This is my code? Any suggestions?
Private Sub Command13_Click()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim strMainDocNm As String
Dim strDataDocNm As String
Dim oRange As Word.Range
SQLStr = "select * from PaymentsOnlyTemp"
'[OrderDate] >#" & Me!txtDate & "#"
MergeAllWord (SQLStr)
' Create an instance of MS Word
Set oApp = CreateObject(Class:="Word.Application")
oApp.Visible = True
'Open the Document
oApp.Documents.Open FileName:="C:\MassCards\Letter.doc"
'Run Merge Against TXT File
Set wdApp = Word.Application
strMainDocNm = "C:\MassCards\Letter.doc"
strDataDocNm = "C:\MassCards\merge.888"
With wdApp
'.DisplayAlerts = False
.Application.Visible = True
Set wdDoc = .Documents.Open(FileName:=strMainDocNm)
With wdDoc
With .MailMerge
.MainDocumentType = wdFormLetters
.OpenDataSource Name:=strDataDocNm, LinkToSource:=True
.Execute
End With
.Close SaveChanges:=False
End With
End With
Set wdApp = Nothing
Set wdDoc = Nothing
End Sub