Festlegen der Eingabeformatvorlage für ein Kombinationsfeld

The following example uses the Style property to change the style of user input of a ComboBox. The user chooses a style by selecting an OptionButton control and then types into the ComboBox to select an item. Wenn Style gleich StyleDropDownList ist, muss der Benutzer ein Element aus der Dropdownliste auswählen. Wenn Style gleich StyleDropDownCombo ist, kann der Benutzer Text in den Textbereich eingeben, um ein Element in der Dropdownliste anzugeben.

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:

  • Zwei OptionButton -Steuerelemente mit der Bezeichnung "OptionButton1" und "OptionButton2".

  • A ComboBox named ComboBox1.

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

Support und Feedback

Haben Sie Fragen oder Feedback zu Office VBA oder zu dieser Dokumentation? Unter Office VBA-Support und Feedback finden Sie Hilfestellung zu den Möglichkeiten, wie Sie Support erhalten und Feedback abgeben können.