Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2001
    KY USA
    Thanked 0 Times in 0 Posts

    An Array of Controls:

    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.


    Access 97 SR2 on Win NT 4.0

  2. #2
    3 Star Lounger
    Join Date
    Feb 2001
    Thanked 0 Times in 0 Posts

    Re: An Array of Controls:

    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?

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Sacramento, California, USA
    Thanked 1 Time in 1 Post

    Re: An Array of Controls:

    Try this approach:

    <pre>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

    '<<do something here>>

    End If 'ctl.ControlSource = ""
    End If 'ctl.Section = acDetail
    End If 'ctl.ControlType = acTextBox

    Next ctl 'in Me.Controls</pre>


Posting Permissions

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