VBA Express
Solved: 462 The remote server machine does not exist or is unavailable [Archive] - VBA Express Forum

PDA

View Full Version : Solved: 462 The remote server machine does not exist or is unavailable



mario_h
02-27-2005, 10:47 AM
I am running this code in Access and I get Error 462 when I run the code more then once.

I only get the error when I add fields to the word document.

Adding properties does not cause any errors.

It only happens on the second or subsequent times

Quitting Access releases whatever does not get released in code.

I use Office 2000 pro and XP SP2

Please help.

Mario

Public Sub CreateTemplate()
On Error GoTo HandleError

Dim oWord As Word.Application
Dim oDocs As Word.Documents
Dim oFields As Word.Fields
Dim oPrps As Object

Dim strWordTemplate As String
Dim strTemplatePath As String

Set oWord = GetObject(, "Word.Application")

strTemplatePath = oWord.Options.DefaultFilePath(wdUserTemplatesPath) & "\"
strWordTemplate = strTemplatePath & "\Normal.dot"

Set oDocs = oWord.Documents
oDocs.add Template:=strWordTemplate, _
NewTemplate:=True, _
DocumentType:=0

Set oPrps = oWord.ActiveDocument.CustomDocumentProperties
oPrps.add Name:="fldTest", _
LinkToContent:=False, _
type:=msoPropertyTypeString, _
value:="valTest"

Set oFields = oWord.ActiveDocument.Fields
'This causes the error: 462 The remote server machine does not exist or is unavailable
'Quitting Access solves the problem
'Something is not released. What?
oFields.add Range:=Selection.Range, _
type:=wdFieldEmpty, text:= _
"DOCPROPERTY ""fldTest"" ", _
PreserveFormatting:=True

With oWord
.ActiveDocument.SaveAs filename:="Test.dot", _
FileFormat:=wdFormatTemplate, _
LockComments:=False, _
Password:="", _
AddToRecentFiles:=True, _
WritePassword:="", _
ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, _
SaveFormsData:=False, _
SaveAsAOCELetter:=False
End With

ExitHere:
Set oFields = Nothing
Set oPrps = Nothing
Set oDocs = Nothing
oWord.Quit
Set oWord = Nothing
Exit Sub

HandleError:
If Err.Number = 429 Then
Set oWord = CreateObject("Word.Application")
Resume Next
Else
MsgBox Err.Number & " " & Error(Err.Number)
Resume ExitHere:
End If

End Sub

Anne Troy
02-27-2005, 11:40 AM
Hi, Mario. I put VBA tags on your code. Check out my signature to learn how. :) Good luck!

TonyJollans
02-27-2005, 12:46 PM
Hi Mario,

I would guess your problem is to do with:

Set oWord = GetObject(, "Word.Application")

This is trying to get a currently existing object - in other words, an instance of Word which is already running.

At the end of your code you do:

oWord.Quit
Set oWord = Nothing

This quits Word and releases the object. Next time you try and do the GetObject, it's no longer there to Get.

mario_h
02-27-2005, 12:56 PM
I am doing that in my exit statement:


ExitHere:
Set oFields = Nothing
Set oPrps = Nothing
Set oDocs = Nothing
oWord.Quit
Set oWord = Nothing

Mario

TonyJollans
02-27-2005, 01:18 PM
Sorry, didn't read enough before I opened my mouth and put my foot in it :)

Anne Troy
02-27-2005, 01:31 PM
Inserting footers again, Tony? ROFLMFAO!!!
:bigkiss:

mario_h
02-27-2005, 01:36 PM
Well I solved the problem by changing:


oFields.add Range:=Selection.Range, _
type:=wdFieldEmpty, text:= _
"DOCPROPERTY ""fldTest"" ", _
PreserveFormatting:=True

to:

oFields.add Range:=oWord.Selection.Range, _
type:=wdFieldEmpty, text:= _
"DOCPROPERTY ""fldTest"" ", _
PreserveFormatting:=True


see also:
http://support.microsoft.com/default.aspx?scid=kb;en-us;189618

forkus2000
03-05-2006, 06:48 PM
sorry guys i have the same problem but the difference is :

i have a webbrowser and when i navigate i click a word document link, open a word document inside a webbrowser.

set mdoc=webbrowser.document


selection.goto what:=wdgotopage, which=wdgotoabsolute,count:=5

and sometimes this code generate error