-
MS Word VB Issue
Ok...I have a MS Words form. I created a textbox in this form.
The other thing that I have is a popup "UserForm" with a listbox.
When an user select any one value from this listbox, I want that value to populate the "textbox".
Here are my codes:
Private Sub CommandButton1_Click()
ActiveDocument.FormFields("TextBox1").Result = Me.ListBox1.Text
Unload Me
End Sub
WHen I run this, I get an '5941' error message. Please advise what I am doing wrong.
Thank you.
Joe
-
Re: MS Word VB Issue
Hey joesmith!
When I created a MS Word Form textbox, the default name was "Text1". Double-check that the box you're trying to modify is called TextBox1. Also are you running the code inside the userform? If not you will need to change the Me.ListBox1.Text to <insert userform name>.ListBox1.Text.
Hope that helps ya!
~AJ
-
Re: MS Word VB Issue
Thanks AJ.
I did make sure the text box is named correctly. But still not working.
in my 'main' document, i am running:
Private Sub txtLeon_GotFocus()
UserForm1.Show
End Sub
In the UserForm1, I am running:
Private Sub CommandButton1_Click()
ActiveDocument.FormFields("txtLeon").Result = Me.ListBox1.Text
Unload Me
End Sub
It seems like the two are not 'communicating' to each other.
Darn, i know i am very close.
Joe
-
Re: MS Word VB Issue
Try this:
Code:
Private Sub CommandButton1_Click()
Dim i As Long
i = Me.ListBox1.ListIndex
If i > -1 Then
ActiveDocument.FormFields("txtLeon").Result = Me.ListBox1.List(i)
Unload Me
Else
MsgBox "Please select a list item"
End If
End Sub
-
Re: MS Word VB Issue
Nope.....still not working; same error message.
I tell ya....i think there is somekind of manual setting that I need to fix in MS Words. It seems like the codes are not recognizing the fields or the form.
Any suggestions?
Thank you.
Joe
-
Re: MS Word VB Issue
That must work if you create correct FormField textbox.
If you use ActiveX textbox or Form textbox then the code must be different.
-
Re: MS Word VB Issue
try replacing the reference to activedocument to the specfic document
documents("document1").
i tested your original code, worked fine (word 2000), whether document was protected (for forms) or not
are you sure that txtleon is a forms textbox, not a controls textbox?