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...b;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.
--
Cheers
macropod
[Microsoft MVP - Word]
"Lenny" <(E-Mail Removed)> wrote in message news:6D23B925-E278-4087-AC6B-(E-Mail Removed)...
> 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