Combo Box

The ComboBox control, an example of which appears in Figure 3-16, allows a selection from a standard group of possible responses presented in a drop-down list. The DropDown List style

Figure 3-15. A UserForm with a TextBox control

is very useful in controlling what the user enters. This style of ComboBox doesn't allow the user to enter any response; the user may only pick from the list. This means you don't need to check for invalid values in your code. Conversely, the DropDown Combo style allows users to enter a value if what they want isn't in the list. As the programmer, you'll have to decide which style to use.

Here's an example of populating a drop-down list with values and then responding to the user's choice by displaying what was picked in a standard Visual Basic MsgBox dialog box:

Private Sub UserForm_Activate() With ComboBox1 .AddItem "Item 1" .AddItem "Item 2" .AddItem "Item 3" End With End Sub

Private Sub ComboBox1_Click()

MsgBox "You choose: " & ComboBox1.List(ComboBox1.ListIndex) End Sub

Was this article helpful?

+1 0

Post a comment