Solved

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

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

773 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