Solved

hiding controls

Posted on 2013-10-25
3
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

756 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