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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkbox range

Status
Not open for further replies.

BSando

Technical User
Jun 29, 2003
73
0
0
AU
Hi all,

I have a word doco with checkboxes and thanks to help I have received I have been able count if the checkboxes are checked. But because I have about 50 check boxes on my form and my form is broken up into sections I want to be able to count the checkboxes by a range, so from checkbox1 - checkbox30.

Someone suggested I use an array but doesn't that only work for excel?

Any way below is my code


Sub CountChecks()
Dim oFld As FormField
Dim i As Integer
For Each oFld In ActiveDocument.FormFields
If oFld.Type = wdFieldFormCheckBox Then
If oFld.Result = True Then i = i + 1
End If
Next

MsgBox "There are " & i & " checked boxes."
End Sub



Some people make things happen, some watch while things happen, and some wonder 'What happened?'
 
Hi BSando,

You say
my form is broken up into sections
The following modified version of the code I previously posted will get the count by Section. If you use Section breaks to delineate the 'sections' in your form, then it is unimportant to the code how many checkboxes are in each Section, or the order in which the checkboxes were inserted.
Code:
Sub CountChecksBySection()
Dim oFld As FormField
Dim oSctn As Section
Dim i As Integer
Dim j As Integer
For Each oSctn In ActiveDocument.Sections
    i = 0
    For Each oFld In oSctn.Range.FormFields
        If oFld.Type = wdFieldFormCheckBox Then
            i = i + 1
            If oFld.Result = True Then j = j + 1
        End If
    Next
    MsgBox "There are " & i & " check boxes in Section " _
    & oSctn.Index & ", of which " & j & " are checked."
Next
End Sub

Cheers

[MS MVP - Word]
 
Thanks. I tried to find the post, but I couldn't find it. I even looked under myThreads

Some people make things happen, some watch while things happen, and some wonder 'What happened?'
 
I am not quite following what you want to do.
But because I have about 50 check boxes on my form and my form is broken up into sections I want to be able to count the checkboxes by a range, so from checkbox1 - checkbox30.

What has the Sections to do with it?

macropod's code will give the number of checkboxes per Section, and the number of those that are checked. Is that sufficient?

I am not getting the "range" aspect, ie. checkbox1 to checkbox30.

faq219-2884

Gerry
My paintings and sculpture
 
Fumei,

my form as about 50 checkboxes on it. but I have broken those checkboxes up in to sections i.e. section 1 = area 1 of store, section 2 = area 2 of store etc.
but I want to have a text field in each section on the form that tallies all of the checkboxes in that section.

Some people make things happen, some watch while things happen, and some wonder 'What happened?'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top