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?
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?