Ciolte Alin Ciolte Alin - 6 months ago 12
Vb.net Question

Visual Basic Office: Make form that send data to textbox in document

So in a Word document I have a form that has combobox1 with items and I have a button.When I press the button the selected value of combobox should be added at the textbox1 that is in the word document
enter image description here
TextBox1 is not recognized by the form only if I add the text box in the form but I need the text box in document

Also the code

Private Sub CommandButton1_Click()
TextBox2.Text = TextBox2.Text & ComboBox1.Text & "*"
End Sub


So ComboBox1 is in form and TextBox2 is in word document

Edit:
Form code :

Private Sub ComboBox1_Change()

End Sub

Private Sub ComboBox1_Click()

End Sub

Private Sub CommandButton1_Click()
ThisDocument.TextBox4.Value = ThisDocument.TextBox4.Value + Me.ComboBox1.Text & "*"
End Sub

Private Sub UserForm_Click()

End Sub

Private Sub UserForm_Initialize()
ComboBox1.List = Array("test1", "test2")
End Sub


This document:

Private Sub TextBox1_Change()

End Sub

Private Sub TextBox2_Change()

End Sub

Answer

Try setting the textbox value within the document itself; it's currently assuming the parent object is the form you are setting from:

ThisDocument.TextBox2.Text = ThisDocument.TextBox2.Text & Me.ComboBox1.Text & "*"