RPC Server is Unavailable

Dembrey

Registered User.
Local time
Today, 04:04
Joined
Mar 6, 2002
Messages
65
Hi all,

Got stuck on this one and can't find out whats wrong:

I have some code which opens a new Word document and then pastes some stuff in from the Db. Everything works OK the first time the code runs but the second time I get the error message "RPC Server is unavailable". Access has to be closed and reopened for it to work again.

Searching the arcives I found this article:

http://www.access-programmers.co.uk/forums/showthread.php?s=&threadid=34881

The final problem of Susan's seems similar but there is no answer.

Here's the code in question (I've chopped out various string handling bits to reduce its size).

---------------------------
Dim WordApp As Object
Dim StrARTemplate As String
Dim StrARDescription As String
Dim strAttachments As String

StrARTemplate = HomePath & "AR_Add_Template.dot"

On Error Resume Next
Set WordApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set WordApp = CreateObject("Word.Application")
End If
On Error GoTo 0

WordApp.Visible = True
WordApp.WindowState = wdWindowStateMaximize
WordApp.Documents.Add Template:=StrARTemplate, NewTemplate:=False

StrARDescription = "Test descriptive text"
StrAttachments = "Test text"

With WordApp.Selection

.Goto what:=wdGoToBookmark, Name:="description"
.TypeText StrARDescription

.Goto what:=wdGoToBookmark, Name:="attachments"
.TypeText strAttachments

End With

DoEvents

If Dir("c:\Div1\AR_Add.doc") <> "" Then Kill "C:\Div1\AR_Add.doc"

'=>Code on next line causes " RPC unavailable" error on second execution of code only
With WordApp.Documents(ActiveDocument.Name)
.SaveAs FileName:="c:\Div1\AR_Add", FileFormat:=wdWordDocument
End With

Set WordApp = Nothing
--------------------------------

The code is behind a button to generate the word doc from a record.

Any help as to why this all goes pear-shaped the second time around much appreciated.
 
I managed to 'solve' this one (although I still don't know why it should work one time then not again ....)

So incase anyone else has this problem here's how I managed to sort it.

The problem seemed to lie with the:"ActiveDocument.Name" in the save document line.

So I just 'captured' the new file name when it is created after the line
"WordApp.Documents.Add ......."
with a
Myfilename = WordApp.ActiveDocument.Name

then used this string to refer to the document in the save statement later.

Blowed if I know why this should work and not the other way, but there you go. Anyway, maybe it'll give someone else a hand later on.

Cheers.
 

Users who are viewing this thread

Back
Top Bottom