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

Automation: Word - Access Remote server does not exist...

Status
Not open for further replies.

JayGoettelmann

Programmer
Jul 8, 2003
3
US
After being stumped by calling Word’s Mail Merge from Access (Office XP. There is no problem in Office 2000), I have written code to copy a word document including bookmarks to a new document then inserting data via code. This works about 25 percent of the time. Other times I’m getting Error 462 Remote server does not exist or is unavailable. I’m guessing that the code is running faster than the automation tasks. I’ve tried inserting loops that call the DoEvents function and DBEngine.idle method to no avail. Any ideas?
<Code>
Dim objWord As Object
Dim objDoc As Word.Document
Dim objNewDoc As New Word.Document
Dim WordNotRunning As Boolean

DoCmd.Hourglass (True)
On Error Resume Next
Set objWord = GetObject(, &quot;Word.Application&quot;)
If Err.Number <> 0 Then WordNotRunning = True
Err.Clear
If WordNotRunning Then
Set objWord = New Word.Application
End If
'Turn error catch back on
On Error GoTo Err_Catch

Set objDoc = GetObject(&quot;C:\MyContract.doc&quot;)
objDoc.Select
'The error usually occurs here
objWord.Selection.Copy
objNewDoc.Bookmarks(&quot;\StartofDoc&quot;).Select
objWord.Selection.Paste
With objNewDoc.PageSetup
.LeftMargin = InchesToPoints(0.7)
.RightMargin = InchesToPoints(0.7)
.TopMargin = InchesToPoints(0.5)
.BottomMargin = InchesToPoints(0.5)
End With
objDoc.Close
</Code>

Thanks a lot,
Jay
 
Hmm, had this problem myself. The solution is to ensure that every call to word is preceded by the reference to word – objWord in your case. Otherwise, your OS gets confused about whether it’s talking to this instance of word, or another.

Check it out – when this error occurs, start your Task Manager, have a look at what processes are running. I’ll bet you have winword in there, but nothing to do with word in your taskbar.

An example:

Dim wrd As Object
Dim MyMerge As Word.MailMerge
Dim EOref As String
Dim ReportPath as String

Set wrd = CreateObject(&quot;Word.Application&quot;)
wrd.Application.Visible = True

ReportPath = “C:\SomeDirectory\”

wrd.Documents.Open Filename:=ReportPath & &quot;SomeDocument.doc&quot;
Set MyMerge = wrd.ActiveDocument.MailMerge
MyMerge.Destination = wdSendToNewDocument
MyMerge.Execute
wrd.Documents(&quot;SomeDocument.doc&quot;).Close SaveChanges:=wdDoNotSaveChanges

For tablecount = 1 To EOcount
wrd.Selection.MoveRight Unit:=wdCell
wrd.Selection.MoveRight Unit:=wdCell
wrd.Selection.MoveRight Unit:=wdCell

wrd.Selection.EndKey Unit:=wdLine, Extend:=wdExtend
EOref = wrd.Selection.Text

EOref = Clean(EOref)

AddTPs wrd, EOref

wrd.Application.Browser.Target = wdBrowseTable
wrd.Application.Browser.Next
Next tablecount

Set wrd = Nothing

Bit of a combination – the first bit does some mail-merging, the next bit moves around inside a word table, finds some text, assigns it to the variable EOref, strips it of blanks, and uses Eoref as a parameter for the function AddTPref.

The point is, all calls to word are preceeded by “wrd.” – without this, it works once, but the next time you try you get the error message you’ve been getting. The only other way is to restart between attempts, and some users get a bit tetchy about having to do that.

Hope this helps!
 
I had the exact same problem. If you search MSDN for &quot; Run-time error '462' &quot; you'll find a full explanation. At first I made sure the calls were preceded by objNewDoc, but it still failed after the first call. I finally figured out that certain = statements needed a reference, too. Try this:

.LeftMargin = objNewDoc.InchesToPoints(0.7)
.RightMargin = objNewDoc.InchesToPoints(0.7)
.TopMargin = objNewDoc.InchesToPoints(0.5)
.BottomMargin = objNewDoc.InchesToPoints(0.5)

That should fix your problem!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top