W
Walter
My document contains a table with a checkbox in the last cell of each row. At
the top of the table is a 'master' checkbox field which can be checked if the
user wants to un/check all the other checkboxes in the table. But there are
two problems:
1) The code works fine to check all boxes, but won't always uncheck all the
boxes. In fact, if I use the master checkbox to check all boxes, then
manually uncheck some boxes, then uncheck the master box, it will set all the
boxes to checked.
Here is my code:
Public Sub CheckAll()
Dim strBkMk As String
With ActiveDocument
For i = 1 To .FormFields.Count
strBkMk = "Check" & i
On Error Resume Next
If .FormFields("Check1").CheckBox.Value = True Then
.FormFields(strBkMk).CheckBox.Value = True
ElseIf .FormFields("Check1").CheckBox.Value = False Then
.FormFields(strBkMk).CheckBox.Value = False
End If
Next
End With
End Sub
The template which creates this document names all the checkboxes as
"Checkn" where "n" is a sequential number. This did function properly the
first time I tried it. Also, I tried replacing the "ElseIf" line with just
"Else", which did not work. After restoring the "ElseIf" line, it ran
properly the first time, but has failed ever since.
2) On a one-page document, with about 26 rows in the table, it takes about
60 seconds to update all the boxes. I would expect this from ActiveX
controls, but shouldn't formfields be faster?
Is it possible to simply select all checkbox formfields in the table (or
document) and set their values to T/F?
the top of the table is a 'master' checkbox field which can be checked if the
user wants to un/check all the other checkboxes in the table. But there are
two problems:
1) The code works fine to check all boxes, but won't always uncheck all the
boxes. In fact, if I use the master checkbox to check all boxes, then
manually uncheck some boxes, then uncheck the master box, it will set all the
boxes to checked.
Here is my code:
Public Sub CheckAll()
Dim strBkMk As String
With ActiveDocument
For i = 1 To .FormFields.Count
strBkMk = "Check" & i
On Error Resume Next
If .FormFields("Check1").CheckBox.Value = True Then
.FormFields(strBkMk).CheckBox.Value = True
ElseIf .FormFields("Check1").CheckBox.Value = False Then
.FormFields(strBkMk).CheckBox.Value = False
End If
Next
End With
End Sub
The template which creates this document names all the checkboxes as
"Checkn" where "n" is a sequential number. This did function properly the
first time I tried it. Also, I tried replacing the "ElseIf" line with just
"Else", which did not work. After restoring the "ElseIf" line, it ran
properly the first time, but has failed ever since.
2) On a one-page document, with about 26 rows in the table, it takes about
60 seconds to update all the boxes. I would expect this from ActiveX
controls, but shouldn't formfields be faster?
Is it possible to simply select all checkbox formfields in the table (or
document) and set their values to T/F?