The remote server machine does not exist or is unavailable, MS Word Mail Merge

ffleitas

Registered User.
Local time
Today, 14:54
Joined
Oct 19, 2009
Messages
14
Buenos dias,

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

On which line does it throw this error?

I have had the same problem in the past with Access and Word, basically somewhere in your code you are using code which works fine if you are coding from Word but is not 100% correct when coding from Access and using the Word library.

Any example is this

Code:
objWord.Close wdDoNotSaveChanges
might be better as
Code:
objWord.Close savechanges:=wdDoNotSaveChanges

thus this might also need something but as I am not familiar with mailmerge I am not sure

Code:
objWord.MailMerge.Destination = wdSendToNewDocument
 
Hi darbid,

Thank you for your response. I changed the code:

objWord.Close wdDoNotSaveChanges to your suggestion of

objWord.Close savechanges:=wdDoNotSaveChanges

nonetheless, I receive the same error of
'The remote server machine does not exist or is unavailable'
on the second execution of the code listed. Yet on the first run it works beautifully. Any other ideas?
Felix
 
I was giving you just an example of a potential problem not the whole solution.

Where exactly do you get this error message. Do you know how to step through your code to see?
 
This is the command that gives the error.

ActiveDocument.SaveAs FileName:=strSaveLocation & strSaveAsName

Please tell me how to do a step through. Thank you.
 
You either need to use objWord with the Saveas

or you need to have an application object and put that in from of the Activedocument
 
I placed objWord. in front of
ActiveDocument.SaveAs FileName:=strSaveLocation & strSaveAsName
and it still displays the error
 
I placed objWord. in front of
ActiveDocument.SaveAs FileName:=strSaveLocation & strSaveAsName
and it still displays the error

Sorry I did edit my last post. objWord is your document so

Code:
objword.activedocument
will not work cause they are the same thing.

If you are going to use activedocument then you need to put the word application object in front of it.
 
I am not sure if I am following you correctly? You mean like the example below?

objWord.ActiveDocument.SaveAs FileName:=strSaveLocation & strSaveAsName

Is there another way of saving a word document that is active?
 
I am currently not on a computer that I can see the VBA Word Objects but I imagine that there are two ways to do this.

1. Your objWord which is a document is the same as ActiveDocument thus you could interchange these. ObjWord.saveas

2. The second was is to use ActiveDocument but to use this you will have to put the Word Application in front of it. wordApp.ActiveDocument
 

Users who are viewing this thread

Back
Top Bottom