?
Solved

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

Posted on 2014-01-30
3
Medium Priority
?
360 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
[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 48

Expert Comment

by:Dale Fye
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 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

718 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