Visible by Tag (1 Viewer)

steve1111

Registered User.
Local time
Today, 05:53
Joined
Jul 9, 2013
Messages
170
Hello all,

I am wondering if I may have something set wrong in Access as setting the visible property is not working correctly. I have used this method in other DBs but is giving me issues, it is not setting the controls to visible.

Code:
Dim ctl As Control

For Each ctl In Me.Controls
    If ctl.Tag = "tHide" Then
        ctl.Visible = True
    End If
Next

pretty straightforward and maybe I am missing something simple. :banghead:

Thanks
 

Ranman256

Well-known member
Local time
Today, 05:53
Joined
Apr 9, 2015
Messages
4,337
you example says :
if HIDE then make visible. (sounds backwards)
Maybe the code is:
Code:
For Each ctl In Me.Controls
    If ctl.Tag = "tHide" Then  ctl.Visible = false
Next

or:
ctl.Visible = ctl.Tag <> "tHide"
 

steve1111

Registered User.
Local time
Today, 05:53
Joined
Jul 9, 2013
Messages
170
No that is not the case, "tHide" is just the arbitrary name on the controls I wish to hide and unhide. I am getting this lack of expected response in several places in my database regardless on the tag name. The code will work correctly if I list out each control I want to alter, but not when looping by tag name....
 

Minty

AWF VIP
Local time
Today, 10:53
Joined
Jul 26, 2013
Messages
10,373
The controls don't have focus do they ?
You can't alter visibility if the control has focus from memory.
 

Minty

AWF VIP
Local time
Today, 10:53
Joined
Jul 26, 2013
Messages
10,373
Wait a mo. Remove the Me.

Code:
For Each ctl In Controls
    If ctl.Tag = "tHide" Then
        ctl.Visible = True
    End If
Next
 

steve1111

Registered User.
Local time
Today, 05:53
Joined
Jul 9, 2013
Messages
170
Hi Minty,

Nothing has the focus. I think I narrowed it down to an issue using Peter's Software Shrinker Stretcher, the third party software to dynamically resize forms and am reaching out that way. When I comment out his open code, my code is working perfectly!
 

steve1111

Registered User.
Local time
Today, 05:53
Joined
Jul 9, 2013
Messages
170
For those who are also using Peter's Software SS, your tags will work if you change the code to:

Code:
For Each ctl In Controls
    [COLOR="Red"]If ctl.Tag Like "*tHide*" Then[/COLOR]
        ctl.Visible = True
    End If
Next
 

isladogs

MVP / VIP
Local time
Today, 10:53
Joined
Jan 14, 2017
Messages
18,261
For those who are also using Peter's Software SS, your tags will work if you change the code to:

Code:
For Each ctl In Controls
    [COLOR="Red"]If ctl.Tag Like "*tHide*" Then[/COLOR]
        ctl.Visible = True
    End If
Next

You also need to comment out the End If line or it won't compile
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:53
Joined
Sep 21, 2011
Messages
14,442
How is the code meant to know which controls to work on, if you do that?

For those who are also using Peter's Software SS, your tags will work if you change the code to:

Code:
For Each ctl In Controls
    [COLOR=Red]If ctl.Tag Like "*tHide*" Then[/COLOR]
        ctl.Visible = True
    End If
Next
 

steve1111

Registered User.
Local time
Today, 05:53
Joined
Jul 9, 2013
Messages
170
I believe it is buried in the code for the Shrinker Stretcher to clear all tags except when in that format. I am not sure how it works it out but I have verified on several sections of the code that this is the fix when using this product.
 

isladogs

MVP / VIP
Local time
Today, 10:53
Joined
Jan 14, 2017
Messages
18,261
I believe it is buried in the code for the Shrinker Stretcher to clear all tags except when in that format. I am not sure how it works it out but I have verified on several sections of the code that this is the fix when using this product.

To repeat Gasman's point in another way:

Your code will now make ALL controls visible.
If you still want to leave some hidden, you will need to amend the code further.
 

Users who are viewing this thread

Top Bottom