Automation Error

W

WC Justice

I am using Access 2002/2003 as a front end for a SQL Server database and
make extensive use of automation to populate Word templates. I have
recently begun to experience the following error message:

"The remote server machine does not exist or is unavailable"

The strange thing is that it never happens on the first try...only on the
second (and subsequent) times, and after more than half of the code has run.
It hangs up at two distinct places: 1) where the code attempts to format
paragraphs and 2) where the code adds a table. Oddly enough, however, if I
hit the Stop/Reset button in the Visual Basic editor between executions I do
not get the error.

As far as I can see, I set all objects to "Nothing", but to no avail. The
basic setup is below

Set WordApp = New Word.Application
strFileLocation = "R:\Data\DocumentTemplates\Filename.dot"

Set WordDoc = WordApp.Documents.Open(strFileLocation, , True)
WordApp.Visible = True

With WordApp.Selection
-
-
- First hang up

Else
.ParagraphFormat.LeftIndent = InchesToPoints(0)
-
-
- Second hang up

WordApp.ActiveDocument.Tables.Add Selection.Range, 1, 3
-
-
-
strFileName = "R:\ExecutableDocuments\Holding\" & dblContractNumber &
".doc"
WordApp.ActiveDocument.SaveAs strFileName

rsRDO.Close
Set rsRDO = Nothing
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
'WordDoc.Close
Set WordDoc = Nothing
Set WordApp = Nothing

In summary
It always works flawlessly under the following two scenarios:
1) First execution upon opening the Access front end; and
2) Executing after hitting Stop/Reset in the Visual Basic editor.

Outside of that, it hangs up on the following two tasks:
1) formatting a paragraph; or
2) adding a table.

I can give more detail if necessary. I hope this makes sense, and thanks in
advance.
 
A

Alex Dybenko

Hi,
probably here
WordApp.ActiveDocument.Tables.Add Selection.Range, 1, 3

instead of Selection.Range
you should use:

WordApp.Selection.Range or .Range in with context

Further more - instead of ActiveDocument better use WordDoc variable

HTH
 
W

WC Justice

Thanks for the quick reply. That fixed the add table issue, but not the
format paragraph issue. I need to format paragraphs in the form of
manipulating indents and to be able to set tabs. The following is now
hanging up (I added this code after writing the initial post).

.ParagraphFormat.TabStops.Add InchesToPoints(3.25), wdAlignTabRight,
wdTabLeaderSpaces

I am also making a custom footer using the following:

ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
.typetext etc.

Once again, the above code always works fine as long as I hit reset between
executions.

I got the above code by recording macros in Word. Apparantly it doesn't
translate that well.

Thanks again!
 
G

Guest

Hi Justice,

I have a similar application and also get the same problem with the
following statements in my code :

....
Doc1.Paragraphs.RightIndent = CentimetersToPoints(-1.85)
....

and also :

....
...Sections(1).Headers(wdHeaderFooterPrimary).Range.ParagraphFormat.TabStops.Add position:=CentimetersToPoints(1.75)
....

I do quite some different word document manipulations which all go well
except for these two.

Have you found the solution yet ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top