Style Property Example for ComboBox
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 StyleDropDownList, the user must choose an item from the drop-down list. When Style is StyleDropDownCombo, 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 Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:
Sub OptionButton1_Click()
Set ComboBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox1")
ComboBox1.Style = 0 '0=fmStyleDropDownCombo
End Sub
Sub OptionButton2_Click()
Set ComboBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox1")
ComboBox1.Style = 2 '2=fmStyleDropDownList
End Sub
Sub Item_Open()
Set ComboBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox1")
Set OptionButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton1")
Set OptionButton2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton2")
For i = 1 To 10
ComboBox1.AddItem "Choice " & i
Next
OptionButton1.Caption = "Select like ComboBox"
OptionButton1.Value = True
ComboBox1.Style = 0 '0=fmStyleDropDownCombo
OptionButton2.Caption = "Select like ListBox"
End Sub