Option buttons: How to get the selected option from a group?

  • Thread starter Thread starter naddad
  • Start date Start date
N

naddad

Hi,

I have a form in which I have yes/no questions. The user has to answer
the questions and at the end i need to display the score.
So I have several groups of 2 option buttons (Yes/No) and I would like
to know how I can find out which option is selected from a group.
Say group1 has "Yes" selected, I would like to have something like the
following:


Code:
--------------------
if group1.selected.label = "Yes" then countYes++ end if
--------------------


Can anyone help me?

Also, while I'm at it, I have about 25 questions so I have 25 groups.
Is there a smarter way to calculate the total score than type in the
line above for each and every group manually?

Thanks all,
 
maybe something like this
dim c as control
for each c in controls
if typename(c)="Option Button" then
if c.value="Yes" then
countyes++
endif
endif
next

(I'm not 100% sure of the typename, but something like this should work)

J
 
thanks, TypeName(c) returns "OptionButton"
But c is a control, is there a way to cast it to an OptionButton so i
recognizes the caption
 
Dim c As Control
For Each c In Controls
If TypeName(c) = "OptionButton" Then
If c.Value = True Then
countYes = countYes + 1
End If
End If
Next

this worked for me

J
 
I'm sorry - i think i misunderstood your need.
you're wanting to count how many option buttons that have "Yes" as the text
are selected.

Dim c As Control
For Each c In Controls
If TypeName(c) = "OptionButton" Then
If c.Value = True And c.Caption = "Yes" Then
countYes = countYes + 1
End If
End If
Next
 
Back
Top