Check if radio button is selected in frames.

papaz87

New Member
Joined
Nov 22, 2017
Messages
12
I tried searching for this but as i dont know the command I can't seem to find the code.
What im trying to do, I think is pretty easy. I have a Userform with two frames with 4 radio buttons in one and 2 radio buttons in another.
The user must select one in both frames when clicking a command button in the userform. When that is done the userform will unload otherwise i want a MsgBox saying that the user need to select a radio button before finishing.

I tried this even though the "value" option doesnt exist for frames....
Code:
 If Frame1.Value And Frame2.Value = True ThenUnload Me
Else: MsgBox "You have to select an option"
End If

I know this doesnt exist for frames.. but what is the option to see if something is selected inside a frame?

Thanks for the help!
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Why not refer to the option buttons directly instead of via the frame(s)?
 
Upvote 0
Ive tried this.. But i cant think of any other way.. This doesnt solve anything right? :rolleyes:

Code:
If optionbutton1.value = true or optionbutton2.value = true or optionbutton3.value = true or optionbutton4.value = true And optionbutton5.value = true or optionbutton6.value = true Then
Unload me
End If
 
Upvote 0
yea. Forgot the msg box..This is what I wrote...

Rich (BB code):
If optionbutton1.value = true or optionbutton2.value = true or optionbutton3.value = true or optionbutton4.value = true And optionbutton5.value = true or optionbutton6.value = true Then
Unload me
Else Msgbox "you need to select an option"
End if


 
Upvote 0
Here is how to loop through the Frame OptionButtons

I will let you do the rest:

Code:
Private Sub CommandButton2_Click()
Dim x As Long
x = 0
    For Each xControl In Frame1.Controls
            If TypeName(xControl) = "OptionButton" Then
                If xControl.Value = True Then x = x + 1
            End If
            
    Next xControl
If x = 0 Then MsgBox "You must select a option button"
End Sub
 
Upvote 0
Really grateful for the help. Didnt know how to loop. But two things about that code. This only loops thru Frame1 and not frame 2. Ive tried just adding an "And" but that didnt work.

Also i need the userform to Unload if the radio buttons are selected.. This is the code ive tried but that didnt work...


Dim x as Long
x = 0
For Each xControl In Frame1.Controls And Frame2.controls
If TypeName(xControl) = "OptionButton" Then
If xControl.Value = True Then x = x + 1
End If

Next xControl
If x = 0 Then MsgBox "You must select a option button"
If x = 1 Then
Unload Me

End Sub
 
Upvote 0
So if any option button in Frame 1 or Frame 2 is selected you want to close the Userform. Is that what you want?
 
Upvote 0
Or no. One needs to be selected in both frame 1 and 2. Only then the command button will close the userform.
 
Upvote 0
Do not understand

first you said yes then you said:

One needs to be selected in both frame 1 and 2<strike></strike>

So what is it?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top