• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1290
  • Last Modified:

Word Dropdown list FormField update with UserControl

I have a dropdown formfield in a protected word document and want to be able to update the form fields value based on the value selected from a UserForm.
Basically if the user selects "Other" from the dropdown list, I open the UserForm. There the user can select from a more extensive dropdown list or enter the value in a textbox. When the user clicks OK on the UserForm, I want the textbox value to be moved to the formfield if it is not null, otherwise the UserForm dropdown select is moved to the formfield (and some error handling if both the Userform dropdown and textbox are null).
So far I have the UserForm opening when other is selected, but how do I update the FormField when the UserForm is closed? Below is what I have so far. Of course it's not working.
Thanks!

MV
Private Sub Cmdclose_Click()
    If TextBox1.Value Is Not Null Then
        ActiveDocument.FormFields("TestName_1").DropDown.AddItem (0)
        ActiveDocument.FormFields("TestName_1").DropDown.Column(0, 0) = TextBox1.Value
        ActiveDocument.FormFields("TestName_1").DropDown.Value = TextBox1.Value
    Else
        ActiveDocument.FormFields("TestName_1").DropDown.AddItem (0)
        ActiveDocument.FormFields("TestName_1").DropDown.Column(0, 0) = ComboBox1.Value
        ActiveDocument.FormFields("TestName_1").DropDown.Value = ComboBox1.Value
    End If
 
    Unload Me
 
End Sub

Open in new window

0
Michael Vasilevsky
Asked:
Michael Vasilevsky
  • 4
1 Solution
 
GrahamSkanRetiredCommented:
Try this. It is tested in Word 2003, but it should also work in 2007.
Private Sub Cmdclose_Click()
    If TextBox1.Value <> "" Then
        ActiveDocument.FormFields("TestName_1").DropDown.ListEntries.Add TextBox1.Value
    Else
        ActiveDocument.FormFields("TestName_1").DropDown.ListEntries.Add ComboBox1.Value
    End If
    Unload Me
End Sub

Open in new window

0
 
Michael VasilevskySolutions ArchitectAuthor Commented:
Yep that adds the item to the list, how about setting the formfield value to the newly added item?
0
 
Michael VasilevskySolutions ArchitectAuthor Commented:
Ok got it. I had to put "Other" as entry 24 and then delete and replace entry 25 to work with the 25 item limit. Below is my final code.
Thanks!

MV
Private Sub Cmdclose_Click()
    If TextBox1.Value <> "" Then
        ActiveDocument.FormFields("TestName_1").DropDown.ListEntries(25).Delete
        ActiveDocument.FormFields("TestName_1").DropDown.ListEntries.Add TextBox1.Value
        ActiveDocument.FormFields("TestName_1").DropDown.Value = 25
    Else
        ActiveDocument.FormFields("TestName_1").DropDown.ListEntries(25).Delete
        ActiveDocument.FormFields("TestName_1").DropDown.ListEntries.Add ComboBox1.Value
        ActiveDocument.FormFields("TestName_1").DropDown.Value = 25
    End If
    
    Unload Me
 
End Sub

Open in new window

0
 
Michael VasilevskySolutions ArchitectAuthor Commented:
Great help thanks!!
0
 
Michael VasilevskySolutions ArchitectAuthor Commented:
Hey GrahamSkan if you want to put a comment on these questions I'll give you those points as well because you provided me the solution in this question:

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Word/Q_24349704.html

http://www.experts-exchange.com/Microsoft/Development/MS_Access/Access_Coding-Macros/Q_24350206.html
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now