次の方法で共有


チェック ボックスとトグル ボタンの Null 状態を許可する

次の例では、 TripleState プロパティを使用して 、CheckBoxToggleButton の有効な値として Null を許可します。 TripleState の値は ToggleButton2 で制御します。 TripleState プロパティの値を基にチェック ボックス (CheckBox) コントロールとトグル ボタン (ToggleButton) コントロールの値を設定できます。 ただし、コントロールの値に Null 値を設定すると、イベントは発生しません。

この例を利用するには、次のコード例をフォームのスクリプト エディターにコピーします。 コードを実行するには、 Open イベントが生じるようにフォームを開く必要があります。 フォームには次のコントロールが含まれている必要があります。

  • チェック ボックス ( CheckBox ) コントロール (CheckBox1)

  • トグル ボタン ( ToggleButton ) コントロール (ToggleButton1)

  • トグル ボタン ( ToggleButton ) コントロール (ToggleButton2)

  • トグル ボタン ( ToggleButton ) コントロール (ToggleButton1)

  • トグル ボタン ( ToggleButton ) コントロール (ToggleButton2)

Sub Item_Open() 
 Set CheckBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CheckBox1") 
 Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton1") 
 Set ToggleButton2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton2") 
 
 CheckBox1.Caption = "Value is True" 
 CheckBox1.Value = True 
 CheckBox1.TripleState = False 
 
 ToggleButton1.Caption = "Value is True" 
 ToggleButton1.Value = True 
 ToggleButton1.TripleState = False 
 
 ToggleButton2.Value = False 
 ToggleButton2.Caption = "Triple State Off" 
End Sub 
 
Sub ToggleButton2_Click() 
 Set CheckBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CheckBox1") 
 Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton1") 
 Set ToggleButton2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton2") 
 
 If ToggleButton2.Value = True Then 
 ToggleButton2.Caption = "Triple State On" 
 CheckBox1.TripleState = True 
 ToggleButton1.TripleState = True 
 Else 
 ToggleButton2.Caption = "Triple State Off" 
 CheckBox1.TripleState = False 
 ToggleButton1.TripleState = False 
 End If 
End Sub 
 
Sub CheckBox1_Click() 
 Set CheckBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CheckBox1") 
 If IsNull(CheckBox1.Value) Then 
 CheckBox1.Caption = "Value is Null" 
 ElseIf CheckBox1.Value = False Then 
 CheckBox1.Caption = "Value is False" 
 ElseIf CheckBox1.Value = True Then 
 CheckBox1.Caption = "Value is True" 
 End If 
End Sub 
 
Sub ToggleButton1_Click() 
 Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton1") 
 If IsNull(ToggleButton1.Value) Then 
 ToggleButton1.Caption = "Value is Null" 
 ElseIf ToggleButton1.Value = False Then 
 ToggleButton1.Caption = "Value is False" 
 ElseIf ToggleButton1.Value = True Then 
 ToggleButton1.Caption = "Value is True" 
 End If 
End Sub

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

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