unhide controls within a frame?

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
476
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I'm trying to get my userform to hide all controls when it opens (Userform_Initialize) EXCEPT for those within a frame.

Unfortunately, this doesn't work:

VBA Code:
For Each ctl In Me.Controls
    ctl.Visible = False
        If TypeName(ctl) = "Frame1" Then ctl.Visible = True
Next ctl

Nor does this (no error when I replace the line of code with this code, but it still remains hidden):

VBA Code:
If TypeName(ctl) = "Frame1" Then ctl.Frame1.Visible = True

The controls inside Frame1 remain hidden.. The code hides all the controls regardless of whether its in Frame1 or not...... ?

Thanks in advance for any help. (y)
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
One way would be to use the .Tag property for frame enclosed controls. In an If block, check if your Tag property has any value at all (or a specific value if need be) and code accordingly. Perhaps

VBA Code:
If TypeName(ctl) = "OptionButton" And ctl.Tag = "myTagValue" Then
  ctl.Visible = True
Else
  ctl.Visible = False
End If
You didn't say what the type is, so I used option button. If there are several types and they're the only one with .Tag property values, then you don't need to specify the type.
 
Upvote 0
Solution
One way would be to use the .Tag property for frame enclosed controls. In an If block, check if your Tag property has any value at all (or a specific value if need be) and code accordingly. Perhaps

VBA Code:
If TypeName(ctl) = "OptionButton" And ctl.Tag = "myTagValue" Then
  ctl.Visible = True
Else
  ctl.Visible = False
End If
You didn't say what the type is, so I used option button. If there are several types and they're the only one with .Tag property values, then you don't need to specify the type.
Awesome. Thank you... I'll give it try after a bit and I'll let you know. (y)
 
Upvote 0
One way would be to use the .Tag property for frame enclosed controls. In an If block, check if your Tag property has any value at all (or a specific value if need be) and code accordingly. Perhaps

VBA Code:
If TypeName(ctl) = "OptionButton" And ctl.Tag = "myTagValue" Then
  ctl.Visible = True
Else
  ctl.Visible = False
End If
You didn't say what the type is, so I used option button. If there are several types and they're the only one with .Tag property values, then you don't need to specify the type.
Thank you, Micron. That worked and did exactly what I needed it to. Not only that, but it made me realize how assigning tag values to other controls in separate frames can allow me to do a couple other things that I was struggling with (like having a single checkbox to control the value of all other checkboxes within a specific frame. )Thanks again!
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,458
Members
452,915
Latest member
hannnahheileen

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