Solved

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

Posted on 2014-01-30
3
341 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
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…
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

708 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

10 Experts available now in Live!

Get 1:1 Help Now