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

MS Word and checkboxes

Status
Not open for further replies.

gmslam

Technical User
Jun 22, 2016
5
US
I have an MS Word 2016 document with a large table with several columns/rows extending around 60 plus pages. The cells are not all the same, however, I do have an enormous amount of legacy checkboxes throughout the document. I have named the bookmarks. I want to be able to only sum approximately 10 of the checkboxes if their value is true. E.g. checkboxes named Cb11e, Cb12E, Cb13E, etc. The sum would then be placed into a legacy textfield named CbTotal. how do I do this because the checkboxes are not in the same column or row, nor do I want to calculate all the checkboxes on the form?

I looked through the information at the link you sent. However, I don't want to loop though all the checkboxes and the checkboxes are not in the same column.
 
Do you have the "checkboxes throughout the document" or "checkboxes on the form", i.e. UserForm? And do you want "to be able to only sum approximately 10 of the checkboxes " (and what do you mean by 'sum'?) or do you want to Count how many out of the 10 are checked?

You may find some information about Word's checkboxes here

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
The checkboxes are throughout the document. I didn't create a form only the document with a table that has multiple rows with various number of merged cells. In the cells I have inserted legacy checkboxes. I want to be able to count only a select few that are checked, approximately 10, and insert the result into a legacy text field.
 
Did you go to the link I provided? Depending on which controls you are using in your document - FormFields or ActiveX-Controls - you have there VBA samples of looping thru the controls, detecting if it is a checkbox, detecting if it is checked, etc.

If you end up using VBA, a better place to ask VBA questions is at forum707

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
Your description suggests you're using formfield checkboxes. The only way you can tally those is via a macro, such as:
Code:
Sub ChkBoxTally()
Dim i As Long, j As Long, StrBkMk As String
Const BkMkArr As String = "Cb11e,Cb12E,Cb13E"
With ActiveDocument
  For i = 0 To UBound(Split(BkMkArr, ","))
    StrBkMk = Split(BkMkArr, ",")(i)
    If .Bookmarks.Exists(StrBkMk) Then
      If .Bookmarks(StrBkMk).Range.FormFields(1).CheckBox.Value = True Then
        j = j + 1
      End If
    End If
  Next
  If .Bookmarks.Exists("Tally") Then .FormFields("Tally").Result = j
End With
End Sub
If you attach the macro to each of the relevant checkbox formfields as an 'on exit' macro, the tally will auto-update. As coded, the tally is output to a text formfield with the internal bookmark name 'Tally".

Cheers
Paul Edstein
[MS MVP - Word]
 
Macropod, I tried that and it throws an error "the requested member of the collection does not exist". I added a text form field named tally as you stated above.
 
On which line do you get the error?

Cheers
Paul Edstein
[MS MVP - Word]
 
Line 9 - stepping from If .bookmarks(StrBkMk)...to j = j +1
 
That suggests whatever bookmark you're referencing via the array when the error occurs is not a bookmark assigned to a formfield checkbox.

Cheers
Paul Edstein
[MS MVP - Word]
 
Can I send you what i have to look at?
 
You could upload the file to a hosting site (e.g. OneDrive), then post a link here.

Cheers
Paul Edstein
[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top