Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2004
    Posts
    115

    Unanswered: Hide multiple fields at once

    I would like to hide multiple fields based on xyz.
    Currently I list all fields with .visible = false

    Is there any way to create a group for multiple fields and just hide the group?

    Thanks

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    You can automate this, using the Tag Property of the Controls whose Visibility needs to be turned on or off.

    In Form Design View
    • Holding down <Shift> and Left-Click on each Control to be made Visible or Invisible, in turn
    • Go to Properties - Other
    • In the Tag Property box, enter Marked, just like that, no Quotes
    • Click on any other Property in the pane

    Now, use the appropriate code to hide or show the Controls:
    Code:
    Dim ctrl As Control
    
    'To hide Controls
    For Each ctrl In Me.Controls
      If ctrl.Tag = "marked" Then
        ctrl.Visible = False
      End If
    Next
    
    
    'To Show Controls
    
    Dim ctrl As Control
    
    For Each ctrl In Me.Controls
      If ctrl.Tag = "marked" Then
        ctrl.Visible = True
      End If
    Next

    To keep the Formatting appropriate, as you move from Record-to-Record, you'll need the same code in the Form_Current event, as well, depending on whatever condition you use.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You can extend the proposition of Missinglinq further to accelerate the process. This is specially useful when they are many controls concerned.

    1. Use the Tag property as suggested by Missinglinq.

    2. In the Declaration section of the Form Module:
    Code:
    Dim m_ColControls As Collection
    3. In the Form_Open event handler:
    Code:
    Dim ctrl As Control
    
    Set m_colControls = New Collection
    For Each ctrl In Me.Controls
      If ctrl.Tag = "marked" Then
         m_colControls.Add ctrl
      End If
    Next
    4. To hide Controls:
    Code:
    Dim ctrl As Control
    
    For Each ctrl In m_colControls 
        ctrl.Visible = False
     Next
    5. To Show Controls:
    Code:
    Dim ctrl As Control
    
    For Each ctrl In m_colControls
        ctrl.Visible = True
    Next
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •