Document Variable vs Bookmark

S

Starbird

I have a template that I have used bookmarks in which work fine, but because
there is a possibility of the data needing to be changed (via userform) after
the original document is created, I am trying to use a document variable
instead.
The following works fine --
ActiveDocument.Bookmarks("MyTest").Range.Text = oForm.txtMyTest.Text

However when I attempt the following, (I set a docvariable named MyTest in
the location where the bookmark previously existed) it fails to populate--
ActiveDocument.Variables("MyTest").Value = oForm.txtMyTest.Text

What am I doing wrong?
Thanks in advance!

SRD
 
J

Jonathan West

Starbird said:
I have a template that I have used bookmarks in which work fine, but
because
there is a possibility of the data needing to be changed (via userform)
after
the original document is created, I am trying to use a document variable
instead.
The following works fine --
ActiveDocument.Bookmarks("MyTest").Range.Text = oForm.txtMyTest.Text

However when I attempt the following, (I set a docvariable named MyTest in
the location where the bookmark previously existed) it fails to populate--
ActiveDocument.Variables("MyTest").Value = oForm.txtMyTest.Text

What am I doing wrong?

You're not updating the docvariable field after you change the value of the
variable. Add this line after

ActiveDocument.Fields.Update
 
J

Jezebel

You need to update fields. If all the fields are in the body of the document
you can simply use

ActiveDocument.Fields.Update

If the fields are in headers, footers or any other StoryRange you need to
update them separately.
 
D

Doug Robbins

Which can usually be done most easily by using

ActiveDocument.PrintPreview
ClosePrintPreview

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
S

Starbird

Thank You!

Jezebel said:
You need to update fields. If all the fields are in the body of the document
you can simply use

ActiveDocument.Fields.Update

If the fields are in headers, footers or any other StoryRange you need to
update them separately.
 

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