2012-10-25 30 views
0

我很難驗證一組單選按鈕,這是我現在使用的代碼,但我不斷收到錯誤消息:Runtime error 438 - Object doesn't support this property or method使用VBA驗證複選框

這是導致問題的代碼。

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 

我如何甲階酚醛這個問題?

+0

是ctl變灰作爲控制? – nutsch

+1

'frPriority'中是否有單選按鈕以外的其他控件?您需要檢查循環中的控件類型 – SWa

回答

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

你問題在於你在循環所有的控件,並且你的一些控件沒有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