Count Checkboxes

G

Greg Maxey

Hi,

Yesterday I created and posted the following crude macro to someone looking
for a way to add up the choices made in a list. The idea being a table with
a column of questions and three columns headed Yes, No, and Maybe. For each
question there is a checkbox in the headed columns. The user needs to tally
the number of checked boxes in each column and display the result in the
final row:

Sub Countboxes()

Dim Yes As Long
Dim No As Long
Dim Maybe As Long
With ActiveDocument
If .FormFields("Yes1").Result = True Then
Yes = Yes + 1
End If
If .FormFields("Yes2").Result = True Then
Yes = Yes + 1
End If
'Repeat adding the above If string for each Yes checkbox.
If .FormFields("No1").Result = True Then
No = No + 1
End If
If .FormFields("No2").Result = True Then
No = No + 1
End If
If .FormFields("Maybe1").Result = True Then
Maybe = Maybe + 1
End If
If .FormFields("Maybe2").Result = True Then
Maybe = Maybe + 1
End If
ActiveDocument.FormFields("Text1").Result = Yes
ActiveDocument.FormFields("Text2").Result = No
ActiveDocument.FormFields("Text3").Result = Maybe

End With
End Sub

For this macro to work, each formfield check box must be named and there
must be three lines of code for each checkbox. OK as is for a small list,
but if it was of any size it is soon too laborious to pursue.

Question. Is it possible to write this something like:
dim FF as formfield
For each FF.type (checkbox) in column "Yes" If result = True Then
Yes = Yes + 1
next FF
For each FF.type(checkbox) in column "NO" If result = True Then
No = No +1
etc.?

Thanks.


--
\\\\///////////
( @ @ )
----oo00---(_)---00oo----
Greg Maxey
A peer in "peer to peer" support
Rockledge, FL
 
G

Greg Maxey

--
\\\\///////////
( @ @ )
----oo00---(_)---00oo----
Greg Maxey
A peer in "peer to peer" support
Rockledge, FL
 
H

Helmut Weber

Hi Greg,
seems to be an en vogue question.
Try giving your formfields systematically names,
for checkboxes in a table: Row x, column y = "RxCy".
From that point on, it's easy.
for each formfield in selection.tables(1)
if Mid(formfield.name, 2, 1) = "3" then ' row 3
if Mid(formfield.name, 4, 1) = "4" then ' column 4
next
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, Win 98
A hint, not a solution!
 
G

Greg Maxey

Helmut,

Thanks for the reply. I see a different approach is workable. I have a
complete macro now that I put together with assistance of Doug and JGM.
Works great.

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top