使用VBAvalidationcheckbox
我很难validation一组单选button,这是我现在使用的代码,但我不断收到错误消息: 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
我怎样才能解决这个问题?
如果您的框架中有非选项button控件types,请使用此选项,首先检查控件types。
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:
你的问题是,你正在循环所有的控件和一些你的控件将不会有一个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