> On May 12, 12:06 am, "Doug Robbins - Word MVP"
> <d...@REMOVECAPSmvps.org> wrote:
[quoted text clipped - 29 lines]
>
> Thanks.
The exact form of the code depends on where you place it (within the
userform's code, such as in the _Click procedure of the OK button; or in the
macro that declares and shows the userform).
If it's in the userform code, it could be something like this:
ActiveDocument.Variables("NameOfVariable").Value = TextBox1.Text
If it's in the calling macro, the left side is the same but "TextBox1" must
be addressed as a property of the userform:
Dim UF As UserForm1
Set UF = New UserForm1
UF.Show
ActiveDocument.Variables("NameOfVariable").Value = UF.TextBox1.Text
Don't take the latter as production code; at the very least, there's more
that needs to be done to make it error-resistant.

Signature
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
Erik Witkop - 15 May 2008 16:07 GMT
> > On May 12, 12:06 am, "Doug Robbins - Word MVP"
> > <d...@REMOVECAPSmvps.org> wrote:
[quoted text clipped - 59 lines]
> Email cannot be acknowledged; please post all follow-ups to the newsgroup so
> all may benefit.
Thanks Jay,
But for the life of me I cannot get this working. This is my code.
1. one form with one field. The form name is UserForm1. The field name
is customer_field.
2. one variable in the word doc named 'customer_var'
My code is this:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Private Sub CommandButton1_Click()
With ActiveDocument
.Variables("customer_var").Value = customer_field.Text
.Fields.Update
End With
End Sub
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
What is not happening, is the docvariable in the word doc never gets
populated. I don't get any debug errors, it simply does not populate
the docvariable in my word doc.
Any thoughts?
Thanks for all your help. There is very little flaming here as long as
you follow the rules. I like that.
Jay Freedman - 15 May 2008 17:38 GMT
> Thanks Jay,
>
[quoted text clipped - 26 lines]
> Thanks for all your help. There is very little flaming here as long as
> you follow the rules. I like that.
You need three pieces, and I suspect you have only two of them.
1. The "field" customer_field is a text entry control on the userform. I
assume that works.
2. The document variable customer_var is only a storage location -- by
itself it's invisible. The code you showed is correct, and it works here.
3. The piece that I think you're missing is a DOCVARIABLE field in the body
of the document to display the value of the document variable. Open the
Insert > Field dialog, select the DocVariable field type, and enter
customer_var in the "New name" box.

Signature
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
Erik Witkop - 16 May 2008 01:03 GMT
> > Thanks Jay,
>
[quoted text clipped - 46 lines]
>
> - Show quoted text -
Jay,
I just made a new fresh word doc and added the variable and it works
like a charm. I must have something bad in my original doc.
Thanks for your patience and your help!!!