Word 2003
The code below was kindly provided by DaveinIowa and works perfectly for what I need, as well as being easy to figure out and I have modified in several different ways to try different things out. One thing I have not been able to figure out and am looking for help with is how I would modify the code if I were using Option Buttons from Controls instead of the Check Box Form Field.
Thanks in advance for any help, and once again thanks to DaveInIowa for this orginal code
Public Sub thread707_1519663()
Dim tb As Table
Dim rw As Row
Dim rg As Range
Dim ff As FormField
Dim col As Integer
Dim good As Integer
Dim bad As Integer
Dim na As Integer
' Set tb to the table with the check boxes ...
Set tb = ThisDocument.Tables(1)
For Each rw In tb.Rows
Set rg = rw.Range
col = 0
For Each ff In rg.FormFields
If (ff.Type = wdFieldFormCheckBox) Then
col = col + 1
If (ff.CheckBox.Value = True) Then
Select Case col
Case 1
good = good + 1
col = 4 'Ignore other checked box(es) on this row
Case 2
bad = bad + 1
col = 4 'Ignore other checked box(es) on this row
Case 3
na = na + 1
End Select
End If
End If
Next
Next
ThisDocument.FormFields("Text1").Result = (good * 10) + (bad * 5)
ThisDocument.FormFields("Text2").Result = good + bad
If (good + bad = 0) Then
ThisDocument.FormFields("Text3").Result = "N/A"
Else
ThisDocument.FormFields("Text3").Result = ((good * 10) + (bad * 5)) / (good + bad)
End If
End Sub
The code below was kindly provided by DaveinIowa and works perfectly for what I need, as well as being easy to figure out and I have modified in several different ways to try different things out. One thing I have not been able to figure out and am looking for help with is how I would modify the code if I were using Option Buttons from Controls instead of the Check Box Form Field.
Thanks in advance for any help, and once again thanks to DaveInIowa for this orginal code
Public Sub thread707_1519663()
Dim tb As Table
Dim rw As Row
Dim rg As Range
Dim ff As FormField
Dim col As Integer
Dim good As Integer
Dim bad As Integer
Dim na As Integer
' Set tb to the table with the check boxes ...
Set tb = ThisDocument.Tables(1)
For Each rw In tb.Rows
Set rg = rw.Range
col = 0
For Each ff In rg.FormFields
If (ff.Type = wdFieldFormCheckBox) Then
col = col + 1
If (ff.CheckBox.Value = True) Then
Select Case col
Case 1
good = good + 1
col = 4 'Ignore other checked box(es) on this row
Case 2
bad = bad + 1
col = 4 'Ignore other checked box(es) on this row
Case 3
na = na + 1
End Select
End If
End If
Next
Next
ThisDocument.FormFields("Text1").Result = (good * 10) + (bad * 5)
ThisDocument.FormFields("Text2").Result = good + bad
If (good + bad = 0) Then
ThisDocument.FormFields("Text3").Result = "N/A"
Else
ThisDocument.FormFields("Text3").Result = ((good * 10) + (bad * 5)) / (good + bad)
End If
End Sub