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!

Changing code to use Option Button instead of Check Box

Status
Not open for further replies.

dham63

Technical User
Sep 18, 2008
15
CA
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
 
Option buttons are ActiveX controls, and have a _Change event.


Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top