MatchFound プロパティ、MatchRequired プロパティ、Change イベント、CheckBox コントロールの例

次の例では、 MatchFound プロパティと MatchRequired プロパティを使用して 、ComboBox の追加の文字マッチングを示します。 マッチングが確定すると、Change イベントが発生します。

この例では、ComboBox の文字列部分が、ComboBox にリストされたアイテムのどれか 1 つと一致する必要があるかどうかを指定します。 ユーザーは 、CheckBox を使用して照合が必要かどうかを指定し、 ComboBox に入力してそのリストから項目を指定できます。

この例を使用するには、以下のサンプル コードをフォームの宣言部分にコピーします。 フォームに以下のものが含まれていることを確認してください。

  • ComboBox1 という名前のコンボ ボックス
  • CheckBox1 という名前のチェック ボックス
Private Sub CheckBox1_Click() 
 If CheckBox1.Value = True Then 
 ComboBox1.MatchRequired = True 
 MsgBox "To move the focus from the " _ 
 & "ComboBox, you must match an entry in " _ 
 & "the list or press ESC." 
 Else 
 ComboBox1.MatchRequired = False 
 MsgBox " To move the focus from the " _ 
 & "ComboBox, just tab to or click " _ 
 & "another control. Matching is optional." 
 End If 
End Sub 
 
Private Sub ComboBox1_Change() 
 If ComboBox1.MatchRequired = True Then 
 'MSForms handles this case automatically 
 Else 
 If ComboBox1.MatchFound = True Then 
 MsgBox "Match Found; matching optional." 
 Else 
 MsgBox "Match not Found; matching " _ 
 & "optional." 
 End If 
 End If 
End Sub 
 
Private Sub UserForm_Initialize() 
Dim i As Integer 
 
For i = 1 To 9 
 ComboBox1.AddItem "Choice " & i 
Next i 
ComboBox1.AddItem "Chocoholic" 
 
CheckBox1.Caption = "MatchRequired" 
CheckBox1.Value = True 
End Sub

サポートとフィードバック

Office VBA またはこの説明書に関するご質問やフィードバックがありますか? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。