rockman
Senior Member
- Local time
- Today, 07:38
- Joined
- May 29, 2002
- Messages
- 190
I'm merging about 10 strings from a form to a number of different Microsoft Word templates. The problem is that a particular template may not need all 10 strings and therefore doesn't have all 10 bookmarks. I get an unexpected error if a particular bookmark doesn't exist.
My code looks like this:
Everything works fine if all of the bookmarks are in the Word template. However, for example, if a particular template doesn't have a DOB bookmark, an error #5101 "This bookmark does not exist." is generated. (This is to be expected and the code is set-up to handle this). However, when the next bookmark GoTo is called (in this example, .GoTo what:=wdGoToBookMark, Name:="SSN"), the code generates an error #5099 "You can specify only one line, footnote, endnote, comment, or field at a time." All subsequent GoTo's also generate the #5099 error.
Any ideas why I'm generating the #5099 error. As usual the error description isn't helping me very much.
Thanks for any input.
Jeff
My code looks like this:
Code:
On Error Resume Next
With WordApp.Selection
.GoTo what:=wdGoToBookMark, Name:="Full Name"
If Err.Number = 0 Then .TypeText txtFullName.Value
.GoTo what:=wdGoToBookMark, Name:="DOB"
If Err.Number = 0 Then .TypeText DOB.Value
.GoTo what:=wdGoToBookMark, Name:="SSN"
If Err.Number = 0 Then .TypeText txtSSN.Value
End With
Any ideas why I'm generating the #5099 error. As usual the error description isn't helping me very much.
Thanks for any input.
Jeff