CheckBoxALL自动检查52其他复选框循环问题 [英] CheckBoxALL to Auto Check 52 other checkboxes Loop Question
问题描述
我在表单上有一个状态列表,用户可以在其中单击适用于表单的各种状态。存在所有状态。选项(CheckBoxALL),如果选中,将选中所有状态复选框。以下是以下代码:
Private Sub CheckBoxALL_Click()
如果CheckBoxAll = True那么
CheckBoxState01 = True
CheckBoxState02 = True
CheckBoxState03 = True
CheckBoxState04 = True
等.....
CheckBoxState52 = True
否则
CheckBoxState01 = False
CheckBoxState02 = False
CheckBoxState03 = False
CheckBoxState04 = False
CheckBoxState05 =错误
CheckBoxState06 = False
等......... CheckBoxState52 = False
结束如果
结束子
_______________________
我的问题是,如果有更简洁的方法来编写此代码而不是我写的方式是因为我还处于VBA学习模式吗?
我尝试过这样的东西,但却出错了:
私人Sub CheckBoxALL_Click()
Dim CheckALL As Boolean
如果CheckALL(CheckBoxALL)。CheckBox.Value = True那么
对于i = 1到52
CheckALL(CheckBoxState0& i).CheckBox.Value = True
Next i
Else
>
For i = 1 to 52
CheckALL(" CheckBoxState0" i).CheckBox.Value = False
Next i
结束如果
结束子
_________________
我的结果到目前为止,编译错误和编码不起作用。有没有人有任何想法?
谢谢,
基思。
I have a list of states on a form, in which the user can click on various states that are applicable to the form. There is a "ALL State" option (CheckBoxALL) in which if selected all of the state checkboxes will be checked. Below is the following code:
Private Sub CheckBoxALL_Click()
If CheckBoxAll = True Then
CheckBoxState01 = True
CheckBoxState02 = True
CheckBoxState03 = True
CheckBoxState04 = True
etc.....
CheckBoxState52 = True
Else
CheckBoxState01 = False
CheckBoxState02 = False
CheckBoxState03 = False
CheckBoxState04 = False
CheckBoxState05 = False
CheckBoxState06 = False
etc.........CheckBoxState52 = False
End If
End Sub
_______________________
My question is if there is a cleaner way to write this code than the way I wrote it since I am still in VBA learning mode?
I tried something like this but it keeps error out:
Private Sub CheckBoxALL_Click()
Dim CheckALL As Boolean
Set CheckALL = ActiveDocument.FormFields("CheckBoxALL").CheckBox. Value
If CheckALL("CheckBoxALL").CheckBox.Value = True Then
For i = 1 To 52
CheckALL("CheckBoxState0" & i).CheckBox.Value = True
Next i
Else
For i = 1 To 52
CheckALL("CheckBoxState0" & i).CheckBox.Value = False
Next i
End If
End Sub
_________________
My result so far has been compile errors and coding that does not work. Does anybody have any ideas??
Thanks,
Keith.
推荐答案
基思。
您可以使用以下代码。
Hi, Keith.
You may use the following code.
甚至更好,Fish,当控件按顺序命名时!但是复选框名称是" CheckBoxState" &安培;我所以
Even better, Fish, when the controls are sequentially named! But the checkbox names are "CheckBoxState" & i so
这篇关于CheckBoxALL自动检查52其他复选框循环问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!