计算窗体复选框控件为真的个数

来源:互联网 发布:2015年贵州省旅游数据 编辑:程序博客网 时间:2024/04/30 04:57

Private Sub Command6_Click()
Dim Ctl As Control
Dim intCount As Integer

For Each Ctl In Me.Controls
If Ctl.ControlType = acCheckBox Then
If Ctl = True Then
intCount = intCount + 1
End If
End If
Next

 

If intCount > 1 Then
MsgBox "你不能选择多于一个选项!"
ElseIf intCount = 0 Then

MsgBox "你不能不选择一个选项!"
ElseIf intCount = 1 Then

MsgBox "你选择正确!"

 

End If

End Sub