Reputation: 51
I have a word document which has lots of pages, and sections which after each step have an ActiveX
control check box.
At the end of the document there is a completion table which has the name of the sections and when the last check box for a certain section is checked, it turns that part of the table green.
So for an example:
SECTION 1:
Text
(Checkbox 1)
moretext
(Checkbox 2)
evenmoretext
(Checkbox 3)
Completion list:
Section 1
What I am trying to achieve is have some vba that will check to see if ALL of the checkboxes are ticked, and then make the section one part on the table at the end green.
I currently have it working so it turns it green but only when then last checkbox (3) is checked.
Is there anyway to do this?
There is also another matter: I have a button at the top of the document that hides a few of the sections throughout the document, which when pressed, checks any checkboxes it is going to be hiding first. (I use page breaks to show which parts I want to hide)
This is a problem however because the ActiveX
checkboxes do not hide, and so I have written some VBA which instead makes them super tiny, and then resizes them after its done.
Here is the vba I have so far:
Private Sub DTSCheckBox_Click()
If (DTSCheckBox.Value = True And AdminCheckBox.Value = True) Then
Section2Complete.Caption = "Complete"
Section2Complete.BackColor = RGB(0, 255, 0)
CheckAndAmmendBy.Caption = UpgradeTechnic.Text
Else
Section2Complete.Caption = "Outstanding"
Section2Complete.BackColor = RGB(255, 0, 0)
CheckAndAmmendBy.Caption = ""
End If
End Sub
Private Sub V4ToV6Button_Click()
ActiveDocument.Sections(2).Range.Font.Hidden = True
ActiveDocument.Sections(4).Range.Font.Hidden = True
ActiveDocument.Sections(6).Range.Font.Hidden = True
ActiveDocument.Sections(8).Range.Font.Hidden = True
Section15Complete.Caption = "": Section15Complete.BackColor = RGB(255, 255, 255)
ActiveDocument.Tables(1).Rows(15).SetHeight 1, wdRowHeightExactly
SQLScriptCheckbox.Value = True
SQLScriptCheckbox.Height = 1
SQLScriptCheckbox.Width = 1
SQLScriptCheckbox.Enabled = False
RestoreEmailScriptCheckBox.Value = True
RestoreEmailScriptCheckBox.Height = 1
RestoreEmailScriptCheckBox.Width = 1
RestoreEmailScriptCheckBox.Enabled = False
SQLCleanScriptCheckBox.Value = True
SQLCleanScriptCheckBox.Height = 1
SQLCleanScriptCheckBox.Width = 1
SQLCleanScriptCheckBox.Enabled = False
SandboxJobHasBeenSetUpCheckBox.Value = True
SandboxJobHasBeenSetUpCheckBox.Width = 1
SandboxJobHasBeenSetUpCheckBox.Height = 1
SandboxJobHasBeenSetUpCheckBox.Enabled = False
End Sub
Upvotes: 1
Views: 8657
Reputation: 6140
I'm not exactly sure what your design is, but assuming you have 3 checkboxes and you want to hide the section if all three are checked or show the section otherwise (including re-showing the section if the user unchecks one of the three), I suggest creating a separate function that updates the format of the section anytime a checkbox is clicked:
Private Sub CheckBox21_Click()
UpdateSection
End Sub
Private Sub CheckBox22_Click()
UpdateSection
End Sub
Private Sub CheckBox23_Click()
UpdateSection
End Sub
Public Sub UpdateSection()
If CheckBox21.Value = True And CheckBox22.Value = True And CheckBox23.Value = True Then
'Code to hide section
Else
'Code to show section
End If
End Sub
Upvotes: 1