PDA

View Full Version : UF Radio Button get value



Emoncada
05-27-2010, 09:48 AM
I have a UF that I have several group of Radion Buttons.

How Can I have the vb code look at group and pull value that's true?


GroupName = Flavor

OptionButtonChocolate = Chocolate
OptionButtonVanilla = Vanilla
OptionButtonStrawberry = Strawberry

I want Range("D5").value = **Which ever value is True**

xld
05-27-2010, 10:06 AM
I think you have to test them all



With Me

Select Case True

Case .OptionButtonChocolate: Range("D5").Value = "Chocolate"
Case .OptionButtonVanilla: Range("D5").Value = "Vanilla"
'etc
End Select
End With

Tinbendr
05-27-2010, 02:37 PM
I use the Tag property of the Frame holding the radiobuttons.

Private Sub obChocolate_Click()
'Chocolate optionbutton
frmFlavor.Tag = "Chocolate"
End Sub
Private Sub obStrawberry_Click()
'Strawberry optionbutton
frmFlavor.Tag = "Strawberry"
End Sub
Private Sub obVanilla_Click()
'Vanilla optionbutton
frmFlavor.Tag = "Vanilla"
End Sub
Private Sub cbProcess_Click()
'Command button to process data
Select Case frmFlavor.Tag
Case "Vanilla"
'Do something here.
Case "Chocolate"
'Do something here.
Case "Strawberry"
'Do something here.
End Select
Unload Me

End Sub

I usually always set one button (most selected maybe) upon userform initalization.

Private Sub UserForm_Initialize()
obVanilla.Value = True
End Sub

xld
05-27-2010, 02:44 PM
Tinbendr,

Why would you set the tag on click, why not set it at form design?

Tinbendr
05-27-2010, 04:42 PM
...why not set it at form design?Well, you couldn't make Frame1.tag (frmFlavors) equal to all the favors at once.

Each time a user clicks a flavor, Frame1.Tag is updated to contain the option selected. Then, I just have to check one variable as to which one is selected. (You have to so this before closing the userform, of course, unless you assign it to a global variable.)

You could loop through all the controls in the frame, but this is easier for my brain to grasp.