Solved

Hide/Visible object controls on selection of combo - Simplified code

Posted on 2014-01-30
3
342 Views
Last Modified: 2014-02-05
I am looking for simplified code that will hide all objects on a form on open of the form and on selection of the dropdown then the necessary controls can be viewed.

ie.  for each ctrl on frm
           ctrl.visible

I know I have used this method before but my memory is not what it use to be.

Thanks,

K
0
Comment
Question by:Karen Schaefer
3 Comments
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39822317
You could use a sub similar to the following, and call it in the After update event of your combo.  Just pass it a value of True or False to hide or reveal the controls on your form.

Private Sub ControlsVisible(IsVisible as boolean)

    Dim ctrl as control

    for each ctrl in me.controls
        ctrl.visible = IsVisible
    Next

EndID
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 39822725
How do you determine the "necessary controls"? If you're going to loop through them, you'll have to have some sort of method to identify the ones that need to be made visible. Many times you'll use the Tag property. This will work if a control belongs to a single group.

Or you can get quite creative with this, and add multiple bits to the Tag property:

1.3.5.6

So if that control needed to be visible when option 1, 3, 5 or 6 were chosen, you'd use loop logic like Dale shows, and extend it a bit:

Dim i as Integer

For each ctrl In Me.Controls
  If Len(ctrl.Tag) > 0 Then
    Dim tags() As String
    tags = Split(ctrl.Tag, ".")

    For i = 0 to Ubound(tags)
      If tags(i) = Me.YourCombo.Column(0) Then
        ctrl.Visible
      End If
    Next i
  End If
Next

Open in new window


So if I select 5 in the combo, it would make visible all controls that contain the value of 5 in any spot. Of course, you'd first want to run a loop that sets ALL controls to Visible = False. Then the routine above would toggle the controls back Visible, based on the value found in the Tag property.
0
 

Author Closing Comment

by:Karen Schaefer
ID: 39837537
thanks that did the trick
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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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…
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…

896 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

12 Experts available now in Live!

Get 1:1 Help Now