Forms, Bookmarks, and Ref Fields

Y

yappernj

Hi,
I am going nuts trying to get this to work; I have followed all of the
posts and the published info on this topic but to no avail. I hope
someone can help.

I am developing large software validation documents. I want to create
a template that automatically launches a UserForm so my customers can
populate the document with information like Software Name, Revision
Number, etc... Some of information will be repeated in several
locations of the final document.

Since I am new to Word VBA, I have been playing around with a small
practice document template. In working with the attachment, I go to
File|New|Document from Template. The UserForm is launched and I enter
the requested info. The bookmarks are populated but the REF fields are
not, no matter what I do. I've placed "With
ActiveDocument.Fields.Update" into the code, I've tried manual field
updates with Cntl+A/F9, and so far nothing has worked.

I am missing something. Can someone help??
BTW, this is Word 2002 on Win2K.
 
Y

yappernj

I thought I could attach the *.dot file but no luck. Anyway, here's the
code associated with the OK button on the USerform.

<vb>
Private Sub CommandButton1_Click()
With ActiveDocument
Bookmarks("SoftwareName").Range.InsertBefore txtSoftwareName
Bookmarks("SoftwareVersion").Range.InsertBefore
txtSoftwareVersion
Fields.Update

End With

Unload Me
UserForm1.Hide

End Sub
</vb>

The bookmarks are filled in automatically; {REF SoftwareName} and {REF
SoftwareVersion} are never updated, no matter what.
 
C

Charles Kenyon

First, the correct formatting for your code is:

Private Sub CommandButton1_Click()
With ActiveDocument
.Bookmarks("SoftwareName").Range.InsertBefore txtSoftwareName
.Bookmarks("SoftwareVersion").Range.InsertBefore
.txtSoftwareVersion
.Fields.Update
End With
Unload Me
UserForm1.Hide
End Sub

Note the periods. They are important.

..Fields.Update will update fields in the body of your document but not those
in headers/footers or the drawing layer.

Finally, although you are inserting text at the bookmark location, you are
not inserting it in the bookmark!
See <URL: http://word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm>.

Hope this helps.
--

Charles Kenyon

See the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 

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