+ Reply to Thread
Results 1 to 5 of 5

Enumerate form items

  1. #1
    Kurt
    Guest

    Enumerate form items

    How can I enumerate form items so that I can, say, change BackColor,
    checkbox status, etc. in a loop?

    or, as an alternative, if I generate the object name ("form1.cb1",
    "form1.cb2", etc) as a string, how can I refer to it using the string?

    Thanks,

    ....kurt



  2. #2
    Bob Phillips
    Guest

    Re: Enumerate form items


    Dim ctl As Control

    For Each ctl In Me.Controls
    Select Case TypeName(ctl)
    Case "CheckBox": MsgBox "checkbox " & ctl.Name
    Case "CommandButton": MsgBox "Button " & ctl.Name
    End Select
    Next ctl


    --
    HTH

    Bob Phillips

    "Kurt" <[email protected]> wrote in message
    news:[email protected]...
    > How can I enumerate form items so that I can, say, change BackColor,
    > checkbox status, etc. in a loop?
    >
    > or, as an alternative, if I generate the object name ("form1.cb1",
    > "form1.cb2", etc) as a string, how can I refer to it using the string?
    >
    > Thanks,
    >
    > ...kurt
    >
    >




  3. #3
    Tom Ogilvy
    Guest

    Re: Enumerate form items

    for i = 1 to 2
    set cbx = form1.controls("cb" & i)
    Next


    or
    sStr = "cb1"

    set cbx = form1.Controls(sStr)
    --
    Regards,
    Tom Ogilvy


    "Kurt" <[email protected]> wrote in message
    news:[email protected]...
    > How can I enumerate form items so that I can, say, change BackColor,
    > checkbox status, etc. in a loop?
    >
    > or, as an alternative, if I generate the object name ("form1.cb1",
    > "form1.cb2", etc) as a string, how can I refer to it using the string?
    >
    > Thanks,
    >
    > ...kurt
    >
    >




  4. #4
    William Benson
    Guest

    Re: Enumerate form items

    Is this a userform, or a worksheet? I have written routines which loop
    through control objects on userforms as follows:

    Dim ctrl as Control
    For Each ctrl In Me.Controls
    If ctrl.Tag = "SpecialItem" Then

    'Do things to all items I have set the Tag property a certain
    way for (i.e., = 'SpecialItem' or whatever)
    End if
    'OR
    If LCASE(left(ctrl.Name,3)) = "ckb" then
    'Do things to items I have named with prefix 'ckb'
    End If
    'OR
    If TypeName(ctrl) = "CheckBox" then
    'Do things to all checkboxes
    End if
    Next ctrl


    Note: The second item - testing the name - does not work if you created the
    control dynamically as a control array,
    such as
    Dim chk(1 to 3) As Control
    Set chk(1) = Controls.Add("Forms.CheckBox.1", True)
    Set chk(2) = Controls.Add("Forms.CheckBox.1", True)
    Set chk(3) = Controls.Add("Forms.CheckBox.1", True)

    because the name property for each will just be "-1"
    "Kurt" <[email protected]> wrote in message
    news:[email protected]...
    > How can I enumerate form items so that I can, say, change BackColor,
    > checkbox status, etc. in a loop?
    >
    > or, as an alternative, if I generate the object name ("form1.cb1",
    > "form1.cb2", etc) as a string, how can I refer to it using the string?
    >
    > Thanks,
    >
    > ...kurt
    >




  5. #5
    Kurt
    Guest

    Re: Enumerate form items

    Thanks to all who replied. This is exactly what I was looking for. [:-)]

    ....kurt


    "Kurt" <[email protected]> wrote in message
    news:[email protected]...
    > How can I enumerate form items so that I can, say, change BackColor,
    > checkbox status, etc. in a loop?
    >
    > or, as an alternative, if I generate the object name ("form1.cb1",
    > "form1.cb2", etc) as a string, how can I refer to it using the string?
    >
    > Thanks,
    >
    > ...kurt
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1