Calculating option buttons on a Word 2007 form

T

TinaR

I posted this to the wrong discussion group earlier....I'm using Word 2007
to create an on-line locked form. There are several questions on the form.
Each question has 5 answers to choose from, for which I'm using Option
Buttons. I want OptionButton 1's value to =1, OptionButton2=2,
OptionButton3=3, etc. At the end of each question, I’d like to display the
value of the option button chosen. Then, at the very end, I'd like to use a
text box where I would like to display the total value of all the
OptionButtons selected. (ie. If there are 5 questions, Option button 4
chosen for each question; the final text box would display 20). Can this be
done? If so, how do I begin?

Thanks in advance!
Tina
 
D

Doug Robbins - Word MVP

Put a TextInput FormField at the end of each question and use the following
code in the ThisDocument object for the document in the Visual Basic Editor

Private Sub OptionButton1_Click()
If OptionButton1.Value = True Then
ActiveDocument.FormFields("Question1").Result = 1
End If
ActiveDocument.Fields.Update
End Sub
Private Sub OptionButton2_Click()
If OptionButton2.Value = True Then
ActiveDocument.FormFields("Question1").Result = 2
End If
ActiveDocument.Fields.Update
End Sub
Private Sub OptionButton3_Click()
If OptionButton3.Value = True Then
ActiveDocument.FormFields("Question1").Result = 3
End If
ActiveDocument.Fields.Update
End Sub
Private Sub OptionButton4_Click()
If OptionButton4.Value = True Then
ActiveDocument.FormFields("Question1").Result = 4
End If
ActiveDocument.Fields.Update
End Sub
Private Sub OptionButton5_Click()
If OptionButton5.Value = True Then
ActiveDocument.FormFields("Question1").Result = 5
End If
ActiveDocument.Fields.Update
End Sub

That will cause the number corresponding to the OptionButton that has its
value set to True to be displayed in the formfield "Question1" Do the same
thing for your other questions

Finally, have a TextInput Formfield that you set to a Calculation type and
in which you set the Expression to be = Question1 + Question2 + Question3 +
etc. to hold the result.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
Joined
Feb 19, 2015
Messages
1
Reaction score
0
This macro saved me a lot of headache, thanks so much.
There is one problem, though, I hope it can be solved:
When one button in a group is selected and later the user changes mind and selects another option button in that group/ question, the value of previously selected button would be still there in the text input and included in the final calculation which is then incorrect !

Thank you
 

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