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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding controls in a user form 1

Status
Not open for further replies.

Mollethewizard

IS-IT--Management
Nov 18, 2002
93
SE
Is there a simple way to make all textboxes, labels and option buttons in a user form not visible when the form initializes?
I know that I can say – me.Textbox1.Visible = False – but if you’ve got a bunch it takes quite a bit of coding.
Is it possible by using For Each?


Later in the initialize event I would like some of them become visible.

Christer
 
When in design mode, select all controls and in the property box set Visible to False. They will become hidden in run time without any additional action.

combo
 
Christer,
Something like this:

Dim ctl as Control
For each ctl in Controls
ctl.Visible = False
Next

Tranman
 
You may browse the Controls collection of your UserForm object.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
It works like a dream!

Tranman you’re my man.

Enjoy your star!

Christer
 
Christer,
Thanks for the star.

It struck me in re-reading your post that you possibly had controls that were not TextBoxes, Labels, and Option Buttons, and you might want to leave them visible.

If you do want to hide only those types of controls, here's how:

Dim ctl as Control

For each ctl in Controls
Select Case ctl.Properties("ControlType")
Case acTextBox, acLabel, acOptionButton
ctl.Visible = False
End Select
Next

Tranman
 
Tranman – the second code is indeed more useful. Thanks! Your code really speeds up my coding of my general user forms.

Christer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top