
チェックボックスの値を取得する方法です。
例
たとえば、このようなフォームにチェックボックス(checkBox1~3)とボタン(buttonOrder)が貼り付けてあるとします。
このボタンをクリックしたときに、チェックが入っているチェックボックスのラベルのキャプションをメッセージボックスに表示してみます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | Private Sub buttonOrder_Click() Dim msg As String If Me .checkBox1.Value Then msg = Controls( Me .checkBox1.LabelName).Caption & vbCrLf End If If Me .checkBox2.Value Then msg = msg & Controls( Me .checkBox2.LabelName).Caption & vbCrLf End If If Me .checkBox3.Value Then msg = msg & Controls( Me .checkBox3.LabelName).Caption End If MsgBox msg End Sub |
1 2 3 4 5 6 7 8 | Private Sub Form_Load() '初期設定(OFF) Me .checkBox1.Value = False Me .checkBox2.Value = False Me .checkBox3.Value = False End Sub |
実行結果

注文ボタンをクリックすると、

スポンサーリンク