Error 462 The remote server machine does not exist or is unavailable

K

kiln

From Access, I need to open Word, merge a document, and leave the merged
doc open. All works fine (pseudo code) except that I am not able to
release the objWord variable at the end of the routine, thus the error
the next time I try to run the merge. Calling Quit closes Word, I need
it kept open.

Public Function Merge()
Dim objWord As Object ' or Word.Application
Dim docResult As Word.Document
Dim docMerge As Word.Document

Dim strPath As String
Dim strDocName As String
Dim strDotName As String
Dim strDBName As String
Dim strPathDocName As String
Dim strPathDotName As String
Dim strPathDBName As String
Dim strPhaseSet As String
Dim strMergeTable As String

Set objWord = New Word.Application
objWord.Documents.Open strPathDotName, False
Set docMerge = ActiveDocument

With docMerge.MailMerge
.OpenDataSource _
Name:=strPathDBName, _
LinkToSource:=True, _
Connection:="TABLE " & strMergeTable, _
SQLStatement:="SELECT * FROM [" & strMergeTable & "]"
.Destination = wdSendToNewDocument
.Execute
End With

' Close the template file
docMerge.Close
' Show word
objWord.Visible = True
Set docResult = ActiveDocument
' Save the merged document to the project file name.

Set docMerge = Nothing
Set docResult = Nothing
Set objWord = Nothing

End Function
 
K

kiln

I have my code working now, but would sure be interested in hearing
about what this issue is about. I trapped for error 462, did a resume
next...it just uses the existing copy of word. There was another error,

Set docResult = ActiveDocument should have been

Set docResult = objWord.ActiveDocument
 

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