Style property example

The following example uses the Style property to change the effect of typing in the text area of a ComboBox.

The user chooses a style by selecting an OptionButton control and then types into the ComboBox to select an item. When Style is fmStyleDropDownList, the user must choose an item from the drop-down list. When Style is fmStyleDropDownCombo, the user can type into the text area to specify an item in the drop-down list.

To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:

  • Two OptionButton controls named OptionButton1 and OptionButton2.
  • A ComboBox named ComboBox1.
Private Sub OptionButton1_Click() 
 ComboBox1.Style = fmStyleDropDownCombo 
End Sub 
 
Private Sub OptionButton2_Click() 
 ComboBox1.Style = fmStyleDropDownList 
End Sub 
 
Private Sub UserForm_Initialize() 
 Dim i As Integer 
 
 For i = 1 To 10 
 ComboBox1.AddItem "Choice " & i 
 Next i 
 
 OptionButton1.Caption = "Select like ComboBox" 
 OptionButton1.Value = True 
 ComboBox1.Style = fmStyleDropDownCombo 
 
 OptionButton2.Caption = "Select like ListBox" 
End Sub

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.