Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UserForm's variables and Word Doc question

Status
Not open for further replies.

MuskyMan

Technical User
Jul 31, 2002
36
US
I have a user form that opens up upon a document being opened.

I've got 3 textboxes and a command button in the Form. I would like the command button to insert in my document the variables from the textboxes. I can't find an example that would show me the code for this..

Thanks
 
You can play with the Find class, the Fields collection or the Bookmarks collection of the document.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
This assumes you have three text formfields ("Text1", "Text2", "Text3") in your document. Also that the textboxes on your form are named TextBox1 etc,. As PHV notes above, you could also use Fields, or Bookmarks to place your variable data. It depends on a number of factors which way you want to go. So this is just an example. This, on click of the button, will grab the text in each textbox on the form, and put it in the named text formfield in the document.

Hope this gives you a start.

Sub CommandButton1_Click()
Dim strText1 as String, strText2 as String, strText3 as String
' pick up variable from textbox on your form
' technically you could use the values of the
' textboxes directly, without using these variables
' but you could be doing something else with the data

strText1 = TextBox1.Text
strText2 = TextBox2.Text
strText3 = TextBox3.Text

ActiveDocument.Formfields("Text1").Result = strText1
ActiveDocument.Formfields("Text2").Result = strText2
ActiveDocument.Formfields("Text3").Result = strText3
End Sub

Gerry
Painting/Sculpture site:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top