Using REF after UserForm filled in

R

Randy

I created a new UserForm for Memo's using the links mentioned here over and
over: Repeating_data.htm, and Dragondrop.com, but after my UserForm window
pops up and I enter To, From, Date and Subject, everything is inserted
properly. The problem is that if I enter a {Ref bmkFrom} code later in the
document nothing gets filled in. It just stays blank. If I try to Protect
the Document, it completely shuts down the document after I fill in the 4
fields mentioned above. How can I get this Ref to work?
Thanks.
 
D

Doug Robbins - Word MVP

If in the template, you define the bookmark when a single space is selected,
so that with the display of bookmarks turned on via Tools>Options>View, the
bookmark looks like [], rather than |, and you are inserting the information
by using .Range.InsertBefore, the information will be inserted inside the []
and can then be reference using a { REF } field.

Alternatively, you can have the code in the userform, create variables in
the document and use {DOCVARIABLE } fields to display the information. You
can insert multiple { DOCVARIABLE } fields for the same variable whereas,
each bookmark has to be unique

With ActiveDocument
.Variables("varFrom").Value = txtFrom
.Fields.Update
End With

is the code you would need in the userform to set the variables.


--
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
 
D

Dave Lett

Hi Randy,

I'm not absolutely positive, but you might want to create and OnExit macro
for your From field. The macro would be something like the following:

ActiveDocument.Fields.Update

HTH,
Dave
 
R

Randy

Thanks for your great response Doug. I've bee playing with the
Range.InsertBefore for a while now and am having trouble. When I run it, my
Document shuts down as soon as I fill in the fields. Is this code ok to use
for the From: variable?
ActiveDocument.Bookmarks("bmkFrom").Range.Text = oForm.txtFrom.Text
ActiveDocument.Bookmarks("bmkFrom").Range.InsertBefore oForm.txtFrom.Text

Thanks.


Doug Robbins - Word MVP said:
If in the template, you define the bookmark when a single space is selected,
so that with the display of bookmarks turned on via Tools>Options>View, the
bookmark looks like [], rather than |, and you are inserting the information
by using .Range.InsertBefore, the information will be inserted inside the []
and can then be reference using a { REF } field.

Alternatively, you can have the code in the userform, create variables in
the document and use {DOCVARIABLE } fields to display the information. You
can insert multiple { DOCVARIABLE } fields for the same variable whereas,
each bookmark has to be unique

With ActiveDocument
.Variables("varFrom").Value = txtFrom
.Fields.Update
End With

is the code you would need in the userform to set the variables.


--
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

Randy said:
I created a new UserForm for Memo's using the links mentioned here over and
over: Repeating_data.htm, and Dragondrop.com, but after my UserForm window
pops up and I enter To, From, Date and Subject, everything is inserted
properly. The problem is that if I enter a {Ref bmkFrom} code later in the
document nothing gets filled in. It just stays blank. If I try to
Protect
the Document, it completely shuts down the document after I fill in the 4
fields mentioned above. How can I get this Ref to work?
Thanks.
 
D

Doug Robbins - Word MVP

All you need is

ActiveDocument.Bookmarks("bmkFrom").Range.InsertBefore txtFrom

--
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

Randy said:
Thanks for your great response Doug. I've bee playing with the
Range.InsertBefore for a while now and am having trouble. When I run it,
my
Document shuts down as soon as I fill in the fields. Is this code ok to
use
for the From: variable?
ActiveDocument.Bookmarks("bmkFrom").Range.Text = oForm.txtFrom.Text
ActiveDocument.Bookmarks("bmkFrom").Range.InsertBefore oForm.txtFrom.Text

Thanks.


Doug Robbins - Word MVP said:
If in the template, you define the bookmark when a single space is
selected,
so that with the display of bookmarks turned on via Tools>Options>View,
the
bookmark looks like [], rather than |, and you are inserting the
information
by using .Range.InsertBefore, the information will be inserted inside the
[]
and can then be reference using a { REF } field.

Alternatively, you can have the code in the userform, create variables in
the document and use {DOCVARIABLE } fields to display the information.
You
can insert multiple { DOCVARIABLE } fields for the same variable whereas,
each bookmark has to be unique

With ActiveDocument
.Variables("varFrom").Value = txtFrom
.Fields.Update
End With

is the code you would need in the userform to set the variables.


--
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

Randy said:
I created a new UserForm for Memo's using the links mentioned here over
and
over: Repeating_data.htm, and Dragondrop.com, but after my UserForm
window
pops up and I enter To, From, Date and Subject, everything is inserted
properly. The problem is that if I enter a {Ref bmkFrom} code later in
the
document nothing gets filled in. It just stays blank. If I try to
Protect
the Document, it completely shuts down the document after I fill in the
4
fields mentioned above. How can I get this Ref to work?
Thanks.
 

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