|
-
Jun 19th, 2008, 04:22 PM
#1
Thread Starter
New Member
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
-
Jun 19th, 2008, 11:38 PM
#2
Lively Member
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
-
Jun 20th, 2008, 12:08 AM
#3
Thread Starter
New Member
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
-
Jun 20th, 2008, 01:38 AM
#4
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
-
Jun 20th, 2008, 12:34 PM
#5
Thread Starter
New Member
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
-
Jun 20th, 2008, 08:05 PM
#6
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.
-
Jun 21st, 2008, 06:18 AM
#7
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?
Last edited by westconn1; Jun 21st, 2008 at 06:26 AM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|