MS Word Mail Merge error "The remote server machine does not exist or is unavailable"
Greetings,
I have researched everywhere on the web and have not been able to figure out the problem with the code below.
When I run this code below for the first time I don't receive any errors. Yet, when I run it for a second time I receive the error message below:
"The remote server machine does not exist or is unavailable"
If I exit MS Access and return to the same program it works well but again the second time it gives the error.
Any help or suggestions?
Thank you.
Felix - Miami, Florida
----------------------------------------------------------------
'Mail Merge with data.txt file as the source
Dim objWord As Word.Document
'Begins Mail Merge
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Requery
DoCmd.RunMacro "mcr_Word_Collection_Delete"
DoCmd.RunMacro "mcr_Word_Collection_Add_part_2"
WriteFlatFile "C:\program files\iqoq\docs\data.txt", ","
Set objWord = GetObject("c:\program files\iqoq\docs\CFF13001_rev_18.docx", "Word.Document")
'Make Word Visible
objWord.Application.Visible = True
'Set Mail Merge Data Source
objWord.MailMerge.OpenDataSource _
Name:="C:\Program Files\iqoq\docs\data.txt", _
LinkToSource:=True
'Execute the mail merge.
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute
objWord.Activate
objWord.Close wdDoNotSaveChanges
'Call finaltable
Set objWord = Nothing
strProtocol = Form_frm_Steps_1.PROTOCOL_DOC_NO.Value
strSaveAsName = strProtocol
strSaveLocation = "C:\Program Files\iqoq\protocols\"
'Message to return if file exists.
strMsg2 = "Do you want to replace the existing file " & strSaveAsName & "?"
'Check if the file exists.
If Dir("C:\Program Files\iqoq\protocols\" & strSaveAsName & "*") <> "" Then
'If file does exist, prompt with warning message.
'Check value of button clicked in message box.
Select Case MsgBox(strMsg2, vbYesNoCancel + vbExclamation)
Case vbYes
'If Yes was chosen, save and overwrite existing file.
ActiveDocument.SaveAs FileName:=strSaveLocation & strSaveAsName
Case vbNo
'If No was chosen, prompt for file name
With Dialogs(wdDialogFileSaveAs)
.Name = strSaveLocation & ""
.Show
End With
Case Else
'If Cancel was chosen, do nothing.
End Select
Else
'If file does not exist, save without prompting.
ActiveDocument.SaveAs FileName:=strSaveLocation & strSaveAsName
End If
Greetings,
I have researched everywhere on the web and have not been able to figure out the problem with the code below.
When I run this code below for the first time I don't receive any errors. Yet, when I run it for a second time I receive the error message below:
"The remote server machine does not exist or is unavailable"
If I exit MS Access and return to the same program it works well but again the second time it gives the error.
Any help or suggestions?
Thank you.
Felix - Miami, Florida
----------------------------------------------------------------
'Mail Merge with data.txt file as the source
Dim objWord As Word.Document
'Begins Mail Merge
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Requery
DoCmd.RunMacro "mcr_Word_Collection_Delete"
DoCmd.RunMacro "mcr_Word_Collection_Add_part_2"
WriteFlatFile "C:\program files\iqoq\docs\data.txt", ","
Set objWord = GetObject("c:\program files\iqoq\docs\CFF13001_rev_18.docx", "Word.Document")
'Make Word Visible
objWord.Application.Visible = True
'Set Mail Merge Data Source
objWord.MailMerge.OpenDataSource _
Name:="C:\Program Files\iqoq\docs\data.txt", _
LinkToSource:=True
'Execute the mail merge.
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute
objWord.Activate
objWord.Close wdDoNotSaveChanges
'Call finaltable
Set objWord = Nothing
strProtocol = Form_frm_Steps_1.PROTOCOL_DOC_NO.Value
strSaveAsName = strProtocol
strSaveLocation = "C:\Program Files\iqoq\protocols\"
'Message to return if file exists.
strMsg2 = "Do you want to replace the existing file " & strSaveAsName & "?"
'Check if the file exists.
If Dir("C:\Program Files\iqoq\protocols\" & strSaveAsName & "*") <> "" Then
'If file does exist, prompt with warning message.
'Check value of button clicked in message box.
Select Case MsgBox(strMsg2, vbYesNoCancel + vbExclamation)
Case vbYes
'If Yes was chosen, save and overwrite existing file.
ActiveDocument.SaveAs FileName:=strSaveLocation & strSaveAsName
Case vbNo
'If No was chosen, prompt for file name
With Dialogs(wdDialogFileSaveAs)
.Name = strSaveLocation & ""
.Show
End With
Case Else
'If Cancel was chosen, do nothing.
End Select
Else
'If file does not exist, save without prompting.
ActiveDocument.SaveAs FileName:=strSaveLocation & strSaveAsName
End If