Getting Value from Option Buttons

PCWL

New Member
Joined
Jun 7, 2012
Messages
34
Hello,

I think this is a very simple question to answer and maybe I'm just missing something. I have created a userform with an OK button:

Code:
Private Sub cmdOK_Click()
    If optStraight = False And optBrick = False Then
        MsgBox "Please select a pattern"
    Else
        Unload frmPattern
    End If
End Sub
I have two options for the user to select a pattern, either "Straight" or "Brick", and a check to make sure that one of the patterns have been selected.

However, I'm having difficulty getting information from the userform to the code I need to use. I created a short macro to see what was going on and I got "False" values regardless of which option button I select.

Code:
        If frmPattern.optStraight.Value = True Then
            MsgBox "Straight"
        ElseIf frmPattern.optBrick.Value = True Then
            MsgBox "Brick"
        Else
            MsgBox frmPattern.optStraight.Value & " " & frmPattern.optBrick.Value
        End If
The output from this is "False False". Why can't I get "True" values?
Edit:
So I just thought of this right after I posted, but I think I'm losing the values when I use the "Unload" command. Is there another method of closing the userform without losing the information?
 
Last edited:
It was working before, just that I was being dumb (Made another message box as another test, and thought that I was getting the second message box). Thanks for all your help!
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,221,418
Messages
6,159,790
Members
451,589
Latest member
Harold14

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