Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 365
  • Last Modified:

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

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
Karen Schaefer
Asked:
Karen Schaefer
1 Solution
 
Dale FyeCommented:
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
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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
 
Karen SchaeferAuthor Commented:
thanks that did the trick
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now