Hide a bunch of contols

R

Richard Stricker

Hi, Got another question. I have several controls on a form that i want to
hide based on a checkbox.

Do i have to specify each control and its label, one at a time, visible or
not visible?

Is there some sort of "canvas" or "enclosure" those fields can be associated
with to make them visible as a group.

I tried grouping them but then didn't have a name for the group to hide it.

Do i have to use a subform to do this?

Thanks for your help with this.

Richard
 
S

Steve

You don't use a subform to do this.

Open your form in dsign view and select all the controls you want to hide.
Open properties, go to the Other tab and enter something such as HideThese
in the Tag property. Now you can write code to cycle through all the
controls on your form and for those with "HideThese" in the Tag property,
you cab make them visible or not visible as desired.

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
[email protected]
 
R

Richard Stricker

Hi Steve, thanks for the suggestion. I will give it a try.

How does the code to cycle through the controls go?
Something like:
For each control on the form (how do you say that?) if the tag is equal to
"Hide These" then

Control.visible (how do you say that?) = false
Next

End if

Thanks for your help on this feature. Honestly, I didn't notice any
advertisement involved.

Richard
 
M

missinglinq via AccessMonster.com

As Steve said
"Open your form in dsign view and select all the controls you want to hide.
Open properties, go to the Other tab and enter something such as HideThese
in the Tag property. Now you can write code to cycle through all the
controls on your form and for those with "HideThese" in the Tag property"

When you enter the "HideThese" in the Tag property, omit the quotation marks.

Now, in the following code, the Checkbox is called HideControls. You can use
this name, or replace it with a name of your choice. Place this code in the
code module for your form.

Private Sub Form_Current()
Dim ctrl As Control
If HideControls Then
For Each ctrl In Me.Controls
If ctrl.Tag = "HideThese" Then
ctrl.Visible = False
End If
Next
Else
For Each ctrl In Me.Controls
If ctrl.Tag = "HideThese" Then
ctrl.Visible = True
End If
Next
End If
End Sub

Private Sub HideControls_Click()
Dim ctrl As Control
If HideControls Then
For Each ctrl In Me.Controls
If ctrl.Tag = "HideThese" Then
ctrl.Visible = False
End If
Next
Else
For Each ctrl In Me.Controls
If ctrl.Tag = "HideThese" Then
ctrl.Visible = True
End If
Next
End If
End Sub

Good Luck!
 
R

Richard Stricker

Hi, thanks for the exact help. I was able to both understand and use the
code you provided.

Your time and knowledge are appreciated!

Richard
 
D

DawnTreader

would this work with multiple groups for each control?

for example if i have 3 controls a, b, and c, that under certain
circumstances i needed all three to not be visible, then under different
circumstances i needed a and b to be visible and c not, and then a different
circumstance i needed b and c but not a... etc.

could i put in a tag "open, closed, submitted, processed" and then use code
to find then in a case select and hide and unhide accordingly?
 
Top