Great tutorial, I just finished and my UserForm works (once). The
fields from the UserForm are placed into the document at the bookmarks
using the .InsertBefore feature. Now I would like to add a 'reset'
button to clear the document (after printing) so it can be filled out
again. If I use the .InsertBefore " ", it just adds a space before my
previous entry. I tried using .Delete but that deleted my bookmark.
Please help.
Cheers then,
Hillsider
hillsider - 12 Jun 2007 21:04 GMT
UPDATE: I figured it out!
'macro to update bookmarks
Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As String)
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
BMRange.Text = TextToUse
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
End Sub
'called like this:
UpdateBookmark "NameOfBookMark", "String to insert"
cheers then,
hillsider
> Great tutorial, I just finished and my UserForm works (once). The
> fields from the UserForm are placed into the document at the bookmarks
[quoted text clipped - 6 lines]
> Cheers then,
> Hillsider
Doug Robbins - Word MVP - 12 Jun 2007 21:06 GMT
The normal procedure would be to create a new document from the template
each time. To do what you want to do however, it would be better to used
document variables and DOCVARIABLE fields instead of bookmarks.
In the code behind the user form, you would use
With ActiveDocument
.Variables("varname1").Value = [somecontrolvalue]
.Variables("varname2").Value = [someothercontrolvalue]
etc
.Range.Fields.Update
End With
and in the template, where you want [somecontrolvalue] to appear, you would
have a { DOCVARIABLE varname1 } field, etc.

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
> Great tutorial, I just finished and my UserForm works (once). The fields
> from the UserForm are placed into the document at the bookmarks using the
[quoted text clipped - 6 lines]
> Cheers then,
> Hillsider