• An Array of Controls:

    • This topic has 2 replies, 3 voices, and was last updated 24 years ago.
    Author
    Topic
    #355783

    Here is the situation: I need to build several forms, each containing several unbound objects. These objects will be written to a single field on a single table. I need to be able to (on open) count the number of controls on the screen.activeform so that I can loop through and write the values from each of the unbound objects. As an example:

    Imagine if you will a form that has 3 unbound objects (text boxes). On open a module is called and determines that their are three unbound textboxes. After they are filled out a submit button is clicked. The submit button will write the values from each of these textboxes into a new record (one line in the table per each textbox) on the table.

    The next form has 5 unbound textboxes. Rather than hard code a module for each form, I’d much rather simply loop through one module for the number of textboxes on the form.

    This may or may not be the most efficient way to do this, however this is the specifications I’ve been given to work with.

    Unfortunately I don’t know enough to ask the right questions in the “Help” section, or in the books at which I’ve looked.

    Thanks in advance.

    Jeff

    Access 97 SR2 on Win NT 4.0

    Viewing 0 reply threads
    Author
    Replies
    • #525451

      One idea that popped into my head was using the tag property to identify each unbound control. This way you could loop through the forms’ controls collection and test the tag property for a certain value – “UB”? – and then do your writes. I’m sure there are other ways to approach this as others may suggest. It might be helpful to know the bigger picture, for instance why the need exists to write these values to another table?

      • #525614

        Try this approach:

        Dim ctl As Control 'holds each control in form
        
        
        'Loop through all the controls
        For Each ctl in Me.Controls
        
          'work with only a particular type 
          'of control
          If ctl.ControlType = acTextBox Then
        
            'work only with controls in Detail
            If ctl.Section = acDetail Then
         
              'work only with unbound controls
              If ctl.ControlSource = "" Then
         
                '<>
        
              End If 'ctl.ControlSource = ""
            End If  'ctl.Section = acDetail 
          End If  'ctl.ControlType = acTextBox 
        
        Next ctl 'in Me.Controls
    Viewing 0 reply threads
    Reply To: An Array of Controls:

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: