Change properties of a userform

M

Mike Archer

Hello -
How do you programically change an optionbutton value permenatly. I want
the default value for an option button to be true every time the userform is
ran after the user selects that optionbutton. I thought that you could just
set it to true when it was checked... Like this:

Private Sub OptionButton1_Click()
Me.OptionButton1.Value = True
End Sub

Private Sub OptionButton2_Click()
Me.OptionButton2.Value = True
End Sub

Private Sub OptionButton3_Click()
Me.OptionButton3.Value = True
End Sub

But it always goes back to the one that I set to true in the properties.
It's probably easy, but I can't figure it out (other than storing the
selection on the workbook and referencing it in the initialization event -
pretty sloppy, I know).
 
A

Ardus Petus

Option buttons are mutually exclusive.
There is only one of them you can set to TRUE.


Private Sub UserForm_Activate()
Me.OptionButton1.Value = True
End Sub

HTH
 
I

Ivan Raiminius

Hi Mike,

maybe I didn't understand your question, but you don't need to use:
Private Sub OptionButton1_Click()
Me.OptionButton1.Value = True
End Sub
to change the value of optionbutton. It changes automatically,
including unchecking all the other optionbuttons in the same
form/tab/frame.

If you need to set value of the optionbutton before you show the
userform to the user, use something like this:
with userform
..optionbutton1.value=true 'sets the default = checked optionbutton1
..show
end with

Regards,
Ivan
 
M

Mike Archer

Thanks to both of you for answering. I didn't present my question very
clearly. Basically I want the user to select an optionbutton and then for
that optionbutton to still be true the next time the userform runs.
 
A

Ardus Petus

I reiterate my solution:

Private Sub UserForm_Activate()
Me.OptionButton1.Value = True
End Sub

HTH
 
M

Mike Archer

I must be missing something. How do I know which one to set to true in the
activate event. If the user checked optionbutton3 the last time the form was
ran, I want optiongbutton3 to be true everytime the form is ran until another
optionbutton is checked.
--
Thanks,
Mike


Ardus Petus said:
I reiterate my solution:

Private Sub UserForm_Activate()
Me.OptionButton1.Value = True
End Sub

HTH
 
A

Ardus Petus

You must link each optionbutton to a specific cell via ControlSource
property (eg: Sheet1!A1)

This way, Excel will show the current selected optionbutton when you run
Userform1.Show

HTH
--
AP

Mike Archer said:
I must be missing something. How do I know which one to set to true in the
activate event. If the user checked optionbutton3 the last time the form
was
ran, I want optiongbutton3 to be true everytime the form is ran until
another
optionbutton is checked.
 

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