使用VBA验证复选框

时间:2012-10-25 19:05:42

标签: excel vba

我无法验证一组单选按钮,这是我正在使用的代码,但我不断收到错误消息:Runtime error 438 - Object doesn't support this property or method

这是导致问题的代码。

For Each ctl In Me.frPriority.Controls
        If ctl.Value = True Then GoTo nxtCheck1
    Next
        MsgBox "You didn't select a priority"
    Exit Sub
nxtCheck1:

引起所有麻烦的线是

If ctl.Value = True Then

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:3)

如果框架中有非选项按钮控制类型,请使用此选项,首先检查控件类型。

For Each ctl In Me.frPriority.Controls
    If TypeOf ctl Is msforms.OptionButton Then
        If ctl.Value = True Then GoTo nxtCheck1
    end if 
Next
        MsgBox "You didn't select a priority"
    Exit Sub
nxtCheck1:

答案 1 :(得分:1)

您的问题是,您正在循环浏览所有控件,并且您的某些控件不具备Value属性。

尝试这样的事情:

For Each ctl In Me.frPriority.Controls
   If TypeOf ctl Is msforms.OptionButton Then
        If ctl.Value = True Then GoTo nxtCheck1
   End if
Next
相关问题