Hiding Multiple Objects at Once...

friedboudinball

Registered User.
Local time
Today, 05:29
Joined
Sep 27, 2011
Messages
39
I understand how to hide individual objects, such as Combo1 (Me.Comb1.Visible = True/False). However, it gets cumbersome to hide/unhide the many objects each time with code.

Is there a way to group all of the objects or hide them all at once?
 
Are the objects you are hiding always the same? If so, you could try creating one function to hide/show them and just call that every time you need it.
 
wow, didn't think about that...thanks!
 
A common way to do this is to set the Tag Properties of the controls you want to hide to, for instance, Marked, then use code like this:
Code:
Dim ctrl As Control

For Each ctrl In Me.Controls
   If ctrl.Tag = "Marked" Then
     ctrl.Visible = False
   End If
Next
To set the Tag Property on a group of Controls, in Form Design View
  1. Holding down the <Shift> Key, select each Controls
  2. Go to Properties - Other
  3. In the Tag Property, key in Marked
Using this method you even can 'tag' multiple groups of Controls, simply using a different Tag Property for each group.

Also note that while you place Quote Marks around 'Marked' in the code, you do not do this when actually entering 'Marked' in the Tag Property box.

Linq ;0)>
 
If your controls can be grouped, you can drop all the controls that you would like to hide into a Tab control, set the Style property of the tab control to None then all you need to do is set the Visible property of just the tab control when you need to.
 
you can also use a similar code to missinglinq's one, but using the control name to indicate the ones that need to be hidden
something like:
if inStr(ctrl.Name, "XX") > 0 then...
 

Users who are viewing this thread

Back
Top Bottom