Solved

hiding controls

Posted on 2013-10-25
3
267 Views
Last Modified: 2013-10-25
Hi,
I have a number of labels on a form and they all have their visible property set to no.
I have given all labels Tag properties depending on which I want visible. So if the user selects "A" from cboRack then all labels with Tag property of "A" will show and all others will not. I am trying to show labels based only on a selection in cboRack.
I have this so far but keep getting an error.

Dim ctrl As Control
    For Each ctrl In Me.Controls
        If ctrl.Tag = cboRack Then
            ctrl.Visible = True
        Else
            ctrl.Visible = False
        End If
    Next

If I take out the else statement it works, but when the user changes the selection in cboRack, the original set of tags are still visible as well as the new selection. I'm trying to hide all labels with tags that are not = to the cboRack selection.

"Can't hide a control that has the focus"

Any help is greatly appreciated
0
Comment
Question by:Stephen Byrom
3 Comments
 
LVL 50

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 250 total points
ID: 39600718
Hi,
pls try

Dim ctrl As Control
    For Each ctrl In Me.Controls
        If ctrl.ControlType = acLabel Then
            If ctrl.Tag = cboRack Then
                ctrl.Visible = True
            Else
                ctrl.Visible = False
            End If
        End If
    Next

Open in new window

Because cboRack is also a Control
Regards
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 250 total points
ID: 39600884
Add a tab control to your form with the following properties:

One Page (tab)
Style = None
Back Style = Transparent

Put all of the controls you need to hide/unhide and/or enable/disable on this tab.
You can now enable / disable the tab control - and subsequently all controls on it with one line of code

Then, based on some condition:
Me.YourTabControlName.Enabled = True  ' False
Me.YourTabControlName.Visible = True  ' False

This is VERY fast also.
0
 
LVL 1

Author Closing Comment

by:Stephen Byrom
ID: 39601205
Both suggestions do the trick and are great, thanks.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question