|
-
Dec 12th, 2005, 03:03 PM
#1
Thread Starter
Lively Member
[RESOLVED] Combo box items
Please help! (And I apologise if this seems overly long).
I am working on a userform in Word 2003. Amongst other things, the form contains several combo boxes. When the form is initialised:
- Items A and B are added to ComboBox1
- Items X, Y, Z, P, Q and R are added to ComboBox2.
Now I am trying to restrict the list of items from ComboBox2 depending on the choice made from ComboBox1. For example if item A is selected in ComboBox1, I would like only X, Y and Z to be available from ComboBox2. But if item B is selected in ComboBox1, I would like only items P, Q and R to available from ComboBox2.
I would also like to load a default value to ComboBox2 depending on the selection made in ComboBox1. For example, if item A is selected from ComboBox1, I would like ComboBox2 to display item X, although X, Y and Z would be available for selection.
The reason I am adding all items to ComboBox2 in the first instance is because there may be occasions when ComboBox1 s left blank, but a choice is still made from ComboBox2.
-
Dec 12th, 2005, 05:04 PM
#2
Re: Combo box items
you can use the change event of the first combobox to determine what values to populate in the second combobox. The attached code will give you the solution as described in your example.
VB Code:
Private Sub ComboBox1_Change()
With Me.ComboBox2
'First remove existing values from Combo2
.Clear
If Me.ComboBox1.Value = "A" Then
'Add the appropriate items for A
.AddItem "X"
.AddItem "Y"
.AddItem "Z"
'Select the first item, as an example
.ListIndex = 0
ElseIf Me.ComboBox1.Value = "B" Then
'Add the appropriate items for B
.AddItem "P"
.AddItem "Q"
.AddItem "R"
'Select the third item, as an example
.ListIndex = 2
Else
'Add all items
.AddItem "X"
.AddItem "Y"
.AddItem "Z"
.AddItem "P"
.AddItem "Q"
.AddItem "R"
'Select the first item, as an example
.ListIndex = 0
End If
End With
End Sub
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Dec 13th, 2005, 02:45 PM
#3
Thread Starter
Lively Member
Re: [RESOLVED] Combo box items
Thanks - perfect solution
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
|