如何循环使用UserForm上的CheckBoxes [英] How to loop through CheckBoxes on UserForm
问题描述
现在我可以使用For Each取消选择循环,但这不适用于取消选中框。继续收到错误:
chB.Value =对象变量或未设置块变量
Private Sub optB_9201_Click()
Dim ctrl As Control
Dim chB As CheckBox
如果Me.optB_9201.Value = True _
和Me.optB_9251.Value = False _
和Me.optB_9301.Value = False然后
Me.img9301_main.Visible = True
Me.frM9301_View.Caption =
Me.frm9301_Equipment.Enabled = True
对于每个ctrl在Me.frm9301_Equipment.Controls
ctrl.Enabled = False
chB.Value = False
下一步ctrl
Me.frM9301_Stand.Enabled = True
每个ctrl在Me.frM9301_Stand.Controls
ctrl .Enabled = True
下一个ctrl
如果
End Sub
如果有人知道如何解决这个问题,将非常感激。
或者:
可能有一个更改事件在UserForm上声明如果CheckBox是Enabled = False Then Value = False。
这样我就不必在每个OptionButton上放入For Each Loop。我尝试过UserForm_Change Sub和UserForm_Click,但是当我这样做时,根本就没有任何效果。
提前感谢
你永远不会向 chb分配任何内容chb
(我根本不知道你需要使用该变量)。你可以这样做:
为每个ctrl在Me.frm9301_Equipment.Controls
ctrl.Enabled = False
ctrl.Value = False
下一个ctrl
只有在 / strong>控件是复选框。如果不是这样,那么只需添加一些if / then逻辑:
为每个ctrl在Me.frm9301_Equipment.Controls
如果TypeName(ctrl)=CheckBox然后
ctrl.Enabled = False
ctrl.Value = False
结束如果
下一个ctrl
I´m loosing my hairs here. What I want to achieve is simply by selecting an OptionButton I want all CheckBoxes on the active form to deselect AND UNCHECK.
Now I can get it to deselect using the For Each Loop but this does not work for unchecking the boxes. Keep getting the error:
chB.Value=Object variable or With block variable not set
Private Sub optB_9201_Click()
Dim ctrl As Control
Dim chB As CheckBox
If Me.optB_9201.Value = True _
And Me.optB_9251.Value = False _
And Me.optB_9301.Value = False Then
Me.img9301_main.Visible = True
Me.frM9301_View.Caption = "Du har valgt CLX-9201NA med følgende konfigurasjon:"
Me.frm9301_Equipment.Enabled = True
For Each ctrl In Me.frm9301_Equipment.Controls
ctrl.Enabled = False
chB.Value = False
Next ctrl
Me.frM9301_Stand.Enabled = True
For Each ctrl In Me.frM9301_Stand.Controls
ctrl.Enabled = True
Next ctrl
End If
End Sub
If anybody knows how to fix this it would be very much appreciated.
Alternatively:
Is is possible to have a change event on the UserForm that states that if an CheckBox is Enabled= False Then Value=False.
This way I would not have to put in the For Each Loop on every OptionButton. I tried the UserForm_Change Sub and UserForm_Click but nothing seems to work at all when I do this.
Thanks in advance
You never Assign anything to chb
(and I'm not sure that you need to use that variable at all). You could do:
For Each ctrl In Me.frm9301_Equipment.Controls
ctrl.Enabled = False
ctrl.Value = False
Next ctrl
This will only work if all controls are CheckBoxes. If that is not the case, then just add some if/then logic:
For Each ctrl In Me.frm9301_Equipment.Controls
If TypeName(ctrl) = "CheckBox" Then
ctrl.Enabled = False
ctrl.Value = False
End If
Next ctrl
这篇关于如何循环使用UserForm上的CheckBoxes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!