Bookmarks 101

L

Lenny

Can someone provide a good source for in-depth information on Bookmarks....
Word help pretty much only covers how or where to insert.

I need to find out if there is a character limit for bookmarks inserted into
a text form field under the 'text form field options'. Also in a current
project, I am working with a group that unlocks a protected form template to
allow for the pulling in of information from an Access database. They have
added their own bookmarks over top of the form field and I am trying to
ascertain whether this is causing some of theh problems they are having.
When I press F5 and select bookmarks, I can see that some of the form fields
are showing two bookmarks (different names) and that other bookmarks in the
form fields are not showing up in the list at all.

Can someone explain a bit more about bookmarks or refer me to a source? My
thanks and regards for all the help the mvp's have provided over the years.

Lenny
 
M

macropod

Hi Lenny,

Bookmarks can be discrete, overlapped or embedded (ie one within another). Formfields can have a bookmark, but they don't have to -
they are assigned one by default but. if you copy & paste a formfield, the copy doesn't get a bookmark.

Text formfields can have as much text as you like, but inputting more than 255 characters into one programmatically isn't as
straightforward as inserting shorter strings. Microsoft provides a workaround at:
http://support.microsoft.com/default.aspx?scid=kb;en-us;163192
Here’s a simpler way:
ActiveDocument.Bookmarks("Name").Range.Fields(1).Result.Text = "My really long string"
Thus:
Sub UpdateFormField(FFName As String, FFText As String)
Dim StrPwd As String, bProt As Boolean
StrPwd = "YourPassword"
StrPwd = ""
With ActiveDocument
If .ProtectionType = wdAllowOnlyFormFields Then
bProt = True
.Unprotect Password:=StrPwd
End If
.Bookmarks(FFName).Range.Fields(1).Result.Text = FFText
If bProt = True Then .Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True, Password:=StrPwd
bProt = False
End With
End Sub
where the calling routine passes both the formfield's name (FFName) and content (FFText) as parameters. For example:
Sub Demo()
UpdateFormField "Text1", "My really long string"
End Sub

If you're populating bookmarks programmatically, it's generally not a good idea to do that with a bookmark that overlaps another on,
or has formfields or bookmarks embedded in it, because of the risk of destroying those objects. Some code for programmatically
updating bookmarks (in an unprotected document) is:
Sub UpdateBookmark (BmkNm as string, NewTxt as string)
Dim BmkRng as Range
With ActiveDocument
If.Bookmarks.Exists(BmkNm) Then
Set BmkRng =.Bookmarks(BmkNm).Range
BmkRng.Text = NewTxt
.Bookmarks.Add BmkNm, BmkRng
End if
End With
Set BmkRng = Nothing
End Sub
where the calling routine passes both the bookmark name (BmkNm) and its new contents (NewTxt) as parameters.
 
J

Jay Freedman

Hi Lenny,

I don't know of any comprehensive writeup of bookmarks, especially in
the unusual circumstances you describe. But there is a lot of ad-hoc
knowledge of their behavior from (sometimes painful) experience.

According to http://support.microsoft.com/?kbid=211489 -- always a
good source for information about "how many" -- a bookmark name can be
up to 40 characters.

Bookmarks of any kind are allowed to overlap or cover the same area.
If problems are occurring because extra bookmarks are applied over
form fields, most likely the problems really result from references to
the wrong bookmarks rather than from the simple fact of there being
two in the same place.

If you want a macro to put text into a form field, it has to refer to
the bookmark name that appears in the field's Properties dialog.
Referring to some other bookmark that covers the same area may have
one of two undesireable effects:

- If the form is unprotected, the inserted text may delete the form
field (the same as overwriting any other text) or it may put the text
before or after the form field, depending on exactly what the macro
code is.

- If the form is still protected, the macro will probably halt with
an error because it's trying to insert the text into a protected area.

If instead the macro code does the proper thing and sets the result of
the form field (using the correct bookmark name from the Properties
dialog to identify the form field), then it is wrong to unprotect the
form first.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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