Ulic Level: Trainee
 Registered: 15-04-2009 Posts: 2
|
Generic Statement for Linking CheckBoxes
I've created a huge checklist in Word 2007 using the Checkbox feature. Some of these checkboxes exist in a hierarchy, for example, say I have a one item shopping list with a checkbox named "Groceries" and one item under that named "Bananas". If "Bananas" is checked the checkbox above it, "Groceries" should also be checked.
I have written a few simple If statement so when a box is clicked it will check or uncheck another box. The second statement is slightly more complex marking as true and locking the checkbox above it in the hierarchy. For the example above CheckBox1 would equate to "Groceries" and CheckBox1a would equate to "Bananas"
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
CheckBox1a.Value = True
End If
End Sub
Private Sub CheckBox1a_Click()
If CheckBox1a.Value = True Then
CheckBox1.Value = True
CheckBox1.Locked = True
Else
CheckBox1.Value = False
CheckBox1.Locked = False
End If
End Sub |
Now I'm literally rewriting this code over and over again for each and every one of these little checkbox hierarchies I have. Can't I just write one If statement referencing a generic CheckBox and use the Call function under these Subs to run it? My question is how do I do that? I've tried a few things but keep running into errors. Something along these lines?
Dim X As Variable
Dim Y As Variable
X = 1
Y = 1a
Private Sub CheckBoxX()
If CheckBox(X).Value = True Then
CheckBox(Y).Value = True
End If
End Sub
Private Sub CheckBoxY()
If CheckBox(Y).Value = True Then
CheckBox(X).Value = True
CheckBox(X).Locked = True
Else
CheckBox(X).Value = False
CheckBox(X).Locked = False
End If
End Sub |
That doesn't work obviously because I have no idea what I'm doing but I hope you get the gist of what I'm trying to do. Thanks in advance for any help.
|