Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count checked boxes in a word table?

Status
Not open for further replies.

andywing

Technical User
Nov 15, 2001
10
GB
What formula do I need in a word table to count the checked checkboxes in the column above? I must have tried every way but the right way!

The document will be a protected form and the checkboxes bookmarked Check1 Check2 etc.

Microsoft Word 2000

Any help gratefully received.

Andy

Andy Wing
Local Government - Systems Administrator
England
 
What are you counting? The number of check boxes, or the number of check boxes that have been checked?

In any case, sorry, there is no formula within Word table parameters themselves to do it. You would have to do it with code, probably as an exit macro on the last one.

Oh and just a fussy point. It is a good idea to name items that are indicative of what they contain, or what they relate to. MaleYesNo (not Check1); HaveDebt (not Check2)

Assumptions:

1. document with three section
2. section 2 has the table with the check boxes
3. following sub is the OnExit macro of the last checkbox. Note you still have to Tab out of the formfield for this to fire.
4. This just puts up a Msgbox with the count, as I don't know where you want that count, or what you want to do with it.

Code:
Sub countCheck()
Dim mField As FormField
Dim i As Integer
Dim r As Range
Set r = ActiveDocument.Sections(2).Range
For Each mField In r.FormFields
    If mField.Type = wdFieldFormCheckBox Then
       If mField.Result = True Then i = i + 1
    End If
Next
Set r = Nothing
MsgBox i & " check boxes are checked."
End Sub



Gerry
 
Thanks Gerry

I was trying to count the number of boxes checked.

I can count the boxes with {=count(check1,check3,check3)}

But not just the checked boxes.

For what I'm doing a macro is inappropriate as the users of the form would not be experienced users.

Many thanks anyway.

All the best,

Andy.

Andy Wing
Local Government - Systems Administrator
England
 
I don't think you quite understood. The macro DOES give the count of the boxes checked. Further, the macro is automatic. The users do not have to do anything. It runs as soon as they finish checking, or not, the last check box.

The question is what do you want to do with the count? The macro counts how many of the check boxes are checked. It returns that number. There you go. You have the number of check boxes checked. This does not have to involve the user at all. It can run completely invisible to the user. So their inexperience is irrelevant.

Please read my previous post carefully, and if you tell me what you want to do with the count of the checked boxes, I am sure I can help you.

Again:
1. the macro can be invisible to the user;
2. it does give the number of the actually checked boxes;
3. but what do you want to do with it???


Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top