return to bookmark on page one after all the way to end of doc

K

Keith G Hicks

word 03
access 2k
vba automation from access

I'm trying to put the # of pages in a bookmark on page one after the entire
doc has been filled in. I set the values of several dozen bookmarks and once
I'm at the end I need to go back to a bookmark on page one and set it's
value but I keep getting "bookmark does not exist" types of errors.

Here's what I have:

Global objWord As Word.Application
Global docWord As Word.Document

'word is opened in a separate function

Set docWord = objWord.Documents.Add(Template:=sWordFormsPath &
"myTemplate.dot")

with docWord

'the next 4 lines all work fine
.Bookmarks("NumPages").Range.Text = 0
.Bookmarks("OwnOpName9").Range.Text = Nz(rs!OwnOpName, "")
.Bookmarks("EntityName9").Range.Text = Nz(rs!CustName, "")
.Repaginate
'the next line crashes
'.Bookmarks("NumPages").Range.Text =
Str(docWord.ComputeStatistics(wdStatisticPages))
'the next line crashes
'.FormFields.Item("NumPages").Result =
Str(docWord.ComputeStatistics(wdStatisticPages))
'the next line crashes
objWord.Selection.GoTo what:=wdGoToBookmark, Name:="NumPages"
'.GoTo what:=wdGoToSection, Name:=3
'.Bookmarks("NumPages").Range.Text =
Str(docWord.ComputeStatistics(wdStatisticPages))

end with

The bookmark "numpages" does exist and when I set it initially to 0 it works
fine.

Thanks,

Keith
 
K

Keith G Hicks

Never mind. My bookmarks are in form fields. I just realized that once the
field is filled in in code, the bookmark no longer exists. I took out the
line that first sets it to 0 and all is good.

Keith
 

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