Solved

hiding controls

Posted on 2013-10-25
3
248 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 49

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 - Access MVP) 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now