Counting checkboxes in a word document

Counting checkboxes in a word document

Post by UGF1bG » Sat, 13 Aug 2005 00:44:13


I have a terrific form I've created, but it has a ton of checkboxes, and I
need to count which ones have been checked out of a certain group (some are
"yes", some "no" and some "n/a"). I need to count how many are checked in
each group so I can do a formula to determine what percent is in each
category. Any thoughts.
--
Thanks - Paula
 
 
 

Counting checkboxes in a word document

Post by Q2h1Y2sgSG » Sat, 13 Aug 2005 01:45:01

Are you talking about a document form or a user form? If a document form,
how are you "grouping" them? By section?

In any case, here's example code that counts all checkboxes (form field type
71) as well as those that are checked, calculates the percentage checked and
displays a message. You'd need to modify the code to count checkboxes group
by group.

Sub CountCheckedBoxes()

Dim fldCheck As FormField
Dim x As Long
Dim y As Long
Dim z As String

x = 0
y = 0

For Each fldCheck In ActiveDocument.FormFields
If fldCheck.Type = 71 Then 'is checkbox
x = x + 1
If fldCheck.CheckBox.Value = True Then
y = y + 1
End If
End If
Next fldCheck

z = Format(y / x, "Percent")

MsgBox "There are " & x & " checkboxes on this form and " & _
y & _
" (" & z & ") " & _
"is/are checked."

End Sub

--
Chuck Henrich
www.ProductivityApps.com