Radio Button Group value using VBA

R

Rashdeep

Hello,
I have a small issue in trying to find out if one of the radio buttons
in the group of radio buttons is clicked. i.e.:
Group: radioGrp1
Radio Button 1: radioBtn1
Radio Button 2: radioBtn2
Radio Button 3: radioBtn3
Command Button: cmdBtn

What value should be expected from the group if a user selects one of
the radio buttons after the user clicks on the Command Button. The
radio buttons are all "unclicked" upon form load and the Command Button
just validates that the user has selected on of the radio buttons.

Thank you for your help.
 
M

Melanie Breden

Hello,
I have a small issue in trying to find out if one of the radio buttons
in the group of radio buttons is clicked. i.e.:
Group: radioGrp1
Radio Button 1: radioBtn1
Radio Button 2: radioBtn2
Radio Button 3: radioBtn3
Command Button: cmdBtn

What value should be expected from the group if a user selects one of
the radio buttons after the user clicks on the Command Button. The
radio buttons are all "unclicked" upon form load and the Command Button
just validates that the user has selected on of the radio buttons.

write the following procedure into the code module from the UserForm:

Private Sub cmdBtn_Click()
MsgBox CheckOptionButton(Me, "radioGrp1")
End Sub

And this function in a standard module:

Function CheckOptionButton(objForm As Object, strGroupName As String) _
As String
Dim ctrl As Control

For Each ctrl In objForm.Controls
If TypeName(ctrl) = "OptionButton" Then
If ctrl.GroupName = strGroupName And ctrl.Value Then
CheckOptionButton = ctrl.Caption
' reset OptionButton
ctrl.Value = False
End If
End If
Next ctrl
End Function

--
Regards
Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)
 

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