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

Remote Server Error

Status
Not open for further replies.

rookery

Programmer
Apr 4, 2002
384
GB
I am writing a MailMerge procedure using the following code. strInput is a string determined by the user thru' an InputBox. The idea is that the Mailmerge document will be created then saved down into the specified directory and then opened again so that the user can make the necessary changes to the body of the letter. Thus when he saves it avoiding the problem about which directory to save it too. My problem is that although this code works fine first time round, it falls over thereafter on this line:

WordApp.Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldDate

The error being: "Remote Server Is Unavailable or Doesnt Exist".

Why is this happening!! Its driving me nuts!

Set WordApp = CreateObject("Word.Application")
Set WordDoc = WordApp.Documents.Add
With WordDoc.MailMerge

.OpenDataSource _
Name:="C:\Folder\Contacts2.mdb", _
ReadOnly:=True, LinkToSource:=True, _
Connection:=TABLE Clients, _
SQLStatement:="SELECT * FROM [Clients]"

With .Fields
.Add Range:=WordApp.Selection.Range, Name:="FullName"
WordApp.Selection.TypeParagraph
.Add Range:=WordApp.Selection.Range, Name:="CompanyName"
WordApp.Selection.TypeParagraph
.Add Range:=WordApp.Selection.Range, Name:="Address1"
WordApp.Selection.TypeParagraph
.Add Range:=WordApp.Selection.Range, Name:="Address2"
WordApp.Selection.TypeParagraph
.Add Range:=WordApp.Selection.Range, Name:="Address3"
WordApp.Selection.TypeParagraph
.Add Range:=WordApp.Selection.Range, Name:="Address4"
WordApp.Selection.TypeParagraph
.Add Range:=WordApp.Selection.Range, Name:="PostTown"
WordApp.Selection.TypeParagraph
.Add Range:=WordApp.Selection.Range, Name:="County"
WordApp.Selection.TypeParagraph
.Add Range:=WordApp.Selection.Range, Name:="PostCode"
WordApp.Selection.TypeParagraph
WordApp.Selection.TypeParagraph
End With
End With
WordApp.Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldDate

strLetter = "You type in your text here."

With WordApp.Selection
.TypeParagraph
.TypeParagraph
.TypeText Text:=strLetter
.TypeParagraph
.TypeParagraph
.TypeText Text:="Yours Sincerely,"
.TypeParagraph
.TypeParagraph
.TypeText Text:="Your Name"
End With

WordDoc.SaveAs ("C:\Folder\" & strInput & ".doc")
WordDoc.Close
WordApp.Application.Quit

Set WordApp = CreateObject("Word.Application")
WordApp.Documents.Open "C:\Folder\" & strInput & ".doc"
WordApp.Visible = True
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top