Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing properties of objects in userform from VB subroutine 1

Status
Not open for further replies.

navyguy

Programmer
Aug 10, 2002
30
US
Hello,

I have created a userform with the vb editor that comes with excel. I added an option button. I also created a frame with varius things in it. I would like to add code to the option button so that the frame is only visible when the option button is selected. How do I do that?

Thanks
 
Hi navyguy,

It depends a bit on how your Option Button is selected, but in a simple case where the form opens with it unselected and the user can click to select it then, in the Form's Initialize event put code to hide the frame ..

Code:
Me!
Code:
FrameName
Code:
.Visible = False

.. and in the Option Button's OnClick event put code to make it visible:

Code:
Me!
Code:
FrameName
Code:
.Visible = True

If the option button is tied to a cell then its value is determined when the form is displayed and you need to act at that time, so, in that case, put code in the Form Initialise event like ..

Code:
If Me!
Code:
OptionButtonName
Code:
 Then
    Me!
Code:
FrameName
Code:
.Visible = True
Else
    Me!
Code:
FrameName
Code:
.Visible = False
End If

Enjoy,
Tony
 
Thanks. Your first example fit my case. It worked great.

One more question. Now how do I get the frame to not be visible when the option button is not selected (ie another option is selected in a set of options)?
 
Hi navyguy,

The easiest way is to put code in the Change event for the Button. As both the Button and the Frame's visibility are simple Booleans you can do it with a single line:

Code:
Private Sub !
Code:
ButtonName
Code:
_Change
Me!
Code:
FrameName
Code:
.Visible = Me!
Code:
ButtonName
Code:
End Sub

This should replace the code in the OnClick event, but you will need to keep the code in the Initialize event to set it right when the form is first displayed.

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top