Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Oct 2003
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Grouping Objects On Form (2000)

    I have a large amount of objects on a form. Half of them pertain to one selection in a option frame, the other half the other option. As the user selects an option in the option frame, half of the objects get visible set to true, the other half false...etc. The IF-THEN statement to manage this is huge. Is there any way to GROUP objects on a form and assign them to a "GROUP_NAME". This could really simplify the IF statement. Where would this have to be declared and the group's objects named? I hope i have explained this clearly enough. Thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Grouping Objects On Form (2000)

    You could use a tab control for this with two pages. Put one group of controls on the first page and the other group on the second page.

    You can set the Style property of the tab control to None (do this at the end, when the design is more or less finished.) Set the value of the tab control in the After Update event of the option group.

    Note: the value of a tab control is zero-based, setting the value to 0 activates the first page etc.

  3. #3
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Grouping Objects On Form (2000)

    Some other options, you can use one of following methods, depending on how complex the form is (how many controls, etc.). If relatively simple form, you can loop thru all controls and identify those you want to manipulate using the control's tag property. Example:

    Private Sub SetGroupPropertyTag()

    Dim ctl As Control

    For Each ctl In Me.Controls
    Select Case ctl.Tag
    Case "A"
    ctl.Visible = (Me.OptGrp1 = 1)
    Case "B"
    ctl.Visible = (Me.OptGrp1 = 2)
    Case "C"
    ctl.Visible = (Me.OptGrp1 = 3)
    End Select
    Next ctl

    Set ctl = Nothing

    End Sub

    In this example, OptGrp1 is name of Option Group whose value determines which controls with specified Tag property to hide or display. You could call this sub on Option Group's After Update event. If a form is complex, looping thru all the controls may not be efficient if only a few need to be manipulated. In this case you could use an array to "group" the controls, then loop thru the array to set a property. Example:

    Private Sub SetGroupPropertyArray()

    Dim strCtl(1 To 3) As String
    Dim n As Integer

    strCtl(1) = "Field1"
    strCtl(2) = "Field2"
    strCtl(3) = "Field3"

    For n = 1 To 3
    Me.Controls(strCtl(n) & "_txt").Visible = False
    Next

    strCtl(1) = "Field4"
    strCtl(2) = "Field5"
    strCtl(3) = "Field6"

    For n = 1 To 3
    Me.Controls(strCtl(n) & "_txt").Visible = True
    Next

    If Not IsEmpty(strCtl) Then Erase strCtl

    End Sub

    In this example you can reference the control by its index in the form's Controls collection, using a string representing the control's Name property. Since there's no such thing as a "control array" in Access like you have in VB6, one of these approaches may be used instead.

    HTH

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Grouping Objects On Form (2000)

    Actually, you could create an array of controls by doing something like this (assuming your controls as named Field1, Field2, etc.):

    <pre>Dim ctlArray(1 to 5) As Control
    Dim intLoop As Integer

    For intLoop = 1 to 5
    Set ctlArray(intLoop) = Me("Field" & intLoop)
    Next intLoop</pre>


    Then you can reference the controls in the array like this:

    <pre>For intLoop = 1 to 5
    ctlArray(intLoop).Enabled = False
    Next intLoop</pre>


    It isn't as automatic as the wizard-created control arrays in VB, but it will provide similar functionality.
    Charlotte

Posting Permissions

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