Hi Jay, I should've have been a bit more specific. This form has multiple
sections with different field types (including checkboxes), and for each
section is a "Completed" checkbox for that section. So I wouldn't want this
script to count all of the checkboxes but only these "Completed" checkboxes.
How can this script be modified to include only the section "Completed"
checkboxes? If there is a better way of doing so I am all ears.
This can be done, but you have to tell the macro how to recognize which ones are
the "Completed" checkboxes. Do they have something specific in their names that
aren't in any other checkbox's name? Or are they formatted with a specific style
that isn't used anywhere else? Or some other unique characteristic that a macro
could use to say "this one should be counted, but that one shouldn't"?
If you don't have any such characteristic yet, probably the easiest one is to
change the names of the "Completed" boxes. When the form is unprotected,
double-click one of these checkboxes to open its Options dialog and change the
entry in the "Bookmark" box. For example, you could name them "Completed1",
"Completed2", etc. where the number is the section number.
Then the For loop in the macro can be rewritten like this:
For i = 1 To TotalCheckBoxes
Set FFld = myDoc.FormFields("Completed" & i)
If FFld.CheckBox.Value = True Then
CheckedBoxes = CheckedBoxes + 1
End If
Next i
This can be rather touchy -- if the value of TotalCheckBoxes is wrong, or if you
don't have a checkbox name for each value of i between 1 and TotalCheckBoxes,
then an error will stop the macro. It's possible to add error checking to catch
these problems; I didn't show it here to keep things simple.
Another approach is to use the For Each as in the original macro, and use a
different If statement in place of "If FFld.Type = wdFieldFormCheckBox Then" to
make sure the name is "Completed" and a number:
If FFld.Name Like "Completed#" Then
Make the same replacement in the CheckboxCount function if you use that.