Reposted from VB5/6 forum:
I've created a VB app to open a Word document and update it, (using bookmarks), with data retrieved from an As/400. (Not all bookmarks are updated during execution.)
It works fine on the first run, but attempting to open/update the document a second time gives "Run-time error 5102: You entered multiple destinations for a page, line, footnote, endnote or comment" when the program attempts to point to the first bookmark for update.
<EDIT> It's beginning to look like the steps this program takes effectively remove the bookmarks, (the bookmarks the program updated are no longer in the document after the first execution). </EDIT>
Any pointers will be greatly appreciated.
NOTE: Following code is inside a With loop:
I've created a VB app to open a Word document and update it, (using bookmarks), with data retrieved from an As/400. (Not all bookmarks are updated during execution.)
It works fine on the first run, but attempting to open/update the document a second time gives "Run-time error 5102: You entered multiple destinations for a page, line, footnote, endnote or comment" when the program attempts to point to the first bookmark for update.
<EDIT> It's beginning to look like the steps this program takes effectively remove the bookmarks, (the bookmarks the program updated are no longer in the document after the first execution). </EDIT>
Any pointers will be greatly appreciated.
NOTE: Following code is inside a With loop:
Code:
Set WordApp = CreateObject("Word.Application")
Set WordDoc = WordApp.Documents.Open(App.Path + "\ElOff.doc")
While Not .EOF
updKey = Trim(!ELKEY)
'Build update string
Set wdRange = WordDoc.GoTo(what:=wdGoToBookmark, Name:=updKey) ' <<<<< ERROR generated here <<<<<
wdRange.Select
WordApp.Selection.TypeText Text:=updString
If Not InList(Left(updKey, 2)) Then
' Build second update string
updKey = Trim(updKey) + "e"
Set wdRange = WordDoc.GoTo(what:=wdGoToBookmark, Name:=Trim(updKey))
wdRange.Select
WordApp.Selection.TypeText Text:=updString
End If
.MoveNext
Wend
.Close
updKey = "UpdDate"
updString = "Updated: " + Format(Now, "mm-dd-yyyy")
Set wdRange = WordDoc.GoTo(what:=wdGoToBookmark, Name:=Trim(updKey))
wdRange.Select
WordApp.Selection.TypeText Text:=updString
Set wdRange = Nothing
WordDoc.Save
WordDoc.Close