Full Version: Using a Tag for visibility
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
rynman47
Hey guys

I'm trying to set the visibility property for controls with a Tag property of "G1" or "G2" to True. Is my logic here correct? I'm sure I'm missing something (as it's not working).

Here's my code:

CODE
  

For Each ctl In Me
        If ctl.Tag = G1 Or G2 Then
        ctl.Visible = True
        End If
Next
ALaRiva
Try
CODE
  

For Each ctl In Me
        If ctl.Tag = "G1" Or ctl.Tag = "G2" Then
        ctl.Visible = True
        End If
Next
Jack Cowley
My best guess, but search Access help for more details...

CODE
Dim ctl as Control

For Each ctl in Me.Controls
If ctl.ControlType = acTextBox Then
...your if ctl.tag... code
End if
Next


Don't forget the Else bit if you want the control to remain hidden....

hth,
Jack

PS. If ctl.Tag = "G1" or if ctl.Tag = "G2" Then
Jack Cowley
Anthony -

You ARE thinking about all those fish you never caught at HB pier...right? wink.gif

Jack
Bob_L
Jack and Anthony each got it partially right but in your case you don't need to check for a text box type so it would just be:

CODE
For Each ctl In Me[color="red"].Controls [/color]        

    If ctl.Tag = [color="red"]"G1" Or ctl.Tag = "G2"[/color] Then      

          ctl.Visible = True        

    End If

Next
ALaRiva
bob,
I missed the .Controls - however, the IF Statement is still malformed.
Jack Cowley
Bob -

Thank goodness someone is clear headed and not affected by the heat or trips to the wine cellar!

Thank you for jumping!!!

Jack
ALaRiva
BAH! He edited it, now I look the fool, laugh.gif
Bob_L
QUOTE
BAH! He edited it, now I look the fool, laugh.gif

only a little <roflmao> laugh.gif
rynman47
Thanks for the help guys. sad.gif
rynman47
Sorry guys - futher to that.

How do you then do the same with labels?
missinglinq
If ctl.ControlType = acTextBox or ctl.ControlType = acLabel Then

The secret to using this kind of code without bombing is to make sure the property you're trying to set is avaiialable to the control type. In other words, you can use the above if you're setting the Visibility property, because both textboxes and labels have a Visibility property. But if you tried to use it to set the Lock property, it would bomb, because labels don't have a Lock property!
Bob_L
QUOTE
If ctl.ControlType = acTextBox or ctl.ControlType = acLabel Then

The secret to using this kind of code without bombing is to make sure the property you're trying to set is avaiialable to the control type. In other words, you can use the above if you're setting the Visibility property, because both textboxes and labels have a Visibility property. But if you tried to use it to set the Lock property, it would bomb, because labels don't have a Lock property!


The code I provided would not necessarily bomb if the .Lock property was used. It would only bomb if a tag of G1 or G2 was on a non-lockable control. So, actually using tags CAN be easier to use as you can put them on certain controls and, as long as you know what has what, you don't need to qualify by part.
Bob_L
QUOTE
Sorry guys - futher to that.

How do you then do the same with labels?

Again - it is the same as with text boxes - the code I provided would make ANY control visible (text box or label, or option group, etc. as long as the tag G1 or G2 was on it.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.