Range works first time only

K

KitCaz

I'm using an MS Access VB script to create a document from a merge template
and to jump to a specific section to build a table of contents.

When I run the code the first time in an Access session, it works just fine.
But if I run the code a second time, my range selections register the
following error instead of valid values: <The remote server machine does not
exist or is unavailable>

I'm setting my WordApp, TOC and MyRange objects to nothing at the end of the
routine and quitting Word, but something residual is hosing up my subsequent
executions. What's up? It's always fine after I close Access and restart,
but I just get one shot each session.

Code fragment:

'create TOC, added 3/2005 cdc
Dim MyTOC As TablesOfContents
Dim myRange As Range
With wordApp.ActiveDocument
Set myRange = wordApp.ActiveDocument.Content
myRange.Find.Execute FindText:="Table Of Contents"
myRange.Goto what:=wdGoToLine, which:=wdGoToNext, Count:=2
Selection.Find.Execute FindText:="Table Of Contents"
Selection.Goto what:=wdGoToLine, which:=wdGoToNext, Count:=2

Set myRange = ActiveDocument.Range(Start:=Selection.Start,
End:=Selection.End)
ActiveDocument.TablesOfContents.Add Range:=myRange, _
UseFields:=False, UseHeadingStyles:=True, _
LowerHeadingLevel:=3, _
UpperHeadingLevel:=1
End With

(P.S. I'm having to do this at all because the TOC I had in the template
gets hosed after my programmatic merge. I posted this original problem but
no one volunteered any ideas, so I thought I'd try this.)

Thanks in advance,

Chris
 
J

Jean-Guy Marcil

KitCaz was telling us:
KitCaz nous racontait que :
I'm using an MS Access VB script to create a document from a merge
template and to jump to a specific section to build a table of
contents.

When I run the code the first time in an Access session, it works
just fine. But if I run the code a second time, my range selections
register the following error instead of valid values: <The remote
server machine does not exist or is unavailable>

See this if it helps:
http://support.microsoft.com/default.aspx?scid=kb;en-us;189618

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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

Similar Threads

table of contents 4
Automating TOC - Custom Styles 1

Top