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

Word

Status
Not open for further replies.

Swi

Programmer
Feb 4, 2002
1,963
US
I am mail merging a comma delimted file to a word document and everything runs well but when the code is ran for a second time I get this message:

Run-time error '462'
The remote server machine does not exist or is unavailable

When I choose debug it highlights this line in my code:

With ActiveDocument.MailMerge

Here is my complete code for this routine:

Private Sub cmdCreateClientLabels_Click()
If Position = -1 Or Position = 0 Then
MsgBox ("There are no labels to create!"), vbInformation, "LABELS"
Exit Sub
End If
Dim Recordsize As String
Dim Sortspec As String
Dim SortProgram As String
Dim Convertspec As String
Dim ConvertProgram As String
SortProgram = "S:\MIRUS500.EXE"
ConvertProgram = "S:\MIRUS218.EXE"
Dim OutputFile As String
Dim OutputFile2 As String
Dim OutputFile3 As String
OutputFile = "P:\Labels\WorkFile.dat"
OutputFile2 = "P:\Labels\Layout.ctl"
OutputFile3 = "P:\Labels\WorkFile2.dat"
Close #2
Close #3
Open OutputFile For Binary Access Write As #2
Open OutputFile For Binary Access Write As #3
Z = DoEvents()
Sortspec = SortProgram & " " & Filename & "*" & "458" & " " & OutputFile & " " & "2" & " " & "-1"
X = Shell(Sortspec, vbHide)
Close #2
Z = DoEvents()
Convertspec = ConvertProgram & " " & OutputFile2 & " " & OutputFile & "*458" & " " & OutputFile3
X = Shell(Convertspec, vbHide)
Close #3

Dim objWord As New Word.Application

objWord.Documents.Open "P:\Labels\CLIENT.doc"
objWord.Visible = False

With ActiveDocument.MailMerge
.Destination = wdSendToPrinter
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = False
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With

Word.Application.Quit (savechaneges = False)
objWord.Quit

frmMain.SetFocus

MsgBox ("Client labels for ") & Filename & " have been printed successfully!", vbInformation, "CLIENT LABELS"

End Sub

Any ideas?
 
I have struggled with that same issue of QUIT for a very long time. I finally surrendered and took a different approach.

I set up a routine to see if a WORD object was already open or not. If yes, the I use GetObject. If no, I use CreateObject.

I have done some initial testing on this but have not put into production for the fire test yet. It appears to be working.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top