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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Drop Down Field

Status
Not open for further replies.

khurley

IS-IT--Management
Nov 14, 2002
44
US
Hi,

I have a WORD template that has a drop down list of 12 or so choices. When protected the user cannot enter a choice of there own (in one of the pre done choices isn't what they want)

How do I make this field behave so that it shows the 12 choices but also allows for a user to type in their own...

i am stumped...

Thanks
Kathy
 
What you need is a ComboBox, which is on the Control Toolbox and can be added to a form. However, you need to use VBA to manipulate it.
 
can anyone elaborate a litte more on that? i am a novice VB person but can a little bit... i just added a combo box to my word doc and now i can't delete it... argh!
 
Depends on how elaborate your needs are.

The simplest way would be to populate the drop down with an "Add Item" choice. Have an exit macro that checks for the contents (Result) of the drop down. If the Result is "Add Item", have that macro run a UserForm with an textbox and an OK button. The user types in whatever, and the OK button adds that text to the drop down field as the content. Remember though the exit macro for formfields runs after you tab out of the field. So the user will select Add Item, and then Tab. That way if someone is not adding, the form flows as normal.

Following assumes: DropDown1 in document, a UserForm1 with TextBox1 and a CommandButton renamed to cmdOK.

Exit macro in a module
********************
Sub AddDropItem()
If ActiveDocument.FormFields("DropDown1").Result = "Add Item" Then
UserForm1.Show
Else
Exit Sub
End If
End Sub

OK Button code on UserForm1
*****************
Private Sub cmdOK_Click()
Dim strAddItem As String

strAddItem = TextBox1.Text
If strAddItem = "" Then
MsgBox "Text to input is blank."
TextBox1.SetFocus
Exit Sub
Else
Dim aDoc As Document
Set aDoc = ActiveDocument
aDoc.FormFields("DropDown1").Result = strAddItem
Set aDoc = Nothing
Unload Me
End If
End Sub

Note that the above will KEEP that added item in the drop down list. Depending (again) on your needs, you may want to have the code remove the drop down completely and have the new result put into a created text formfield at the same location.

You would also need some error trapping (beyond my simple check for blank - "") on the user input - what if they enter gibberish?

Do you want to keep the added item in the list?

Hope this helps.


Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top