Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to change index of control? 1

Status
Not open for further replies.

andzejek

MIS
Sep 1, 2007
154
US
Is there a way to change index(not a tab index) of control like a textbox?

Andrew
 
How about simply changing the "Option Value" property of the control?


 
Option Value" property? What you mean? How can I do that?
 
Since you said "not the tab index" I assumed you meant a group of controls inside an option frame.

If that's not the case, I guess you mean which index it is within the Controls collection of a form? I.e.

Me.Controls(index)

Then no, I don't think you can.

If you explain what you want to do, somebody can probably give you a suggestion of doing it without knowing the index.


 
Index within the Controls collection is set during controls creation in order as they were created. Now I want to go through these controls and do "something" but not through all of them and not in order as they were created.
 
How about setting the Tag property of the controls you want to do "Something" to?
Code:
    Dim ctl As Control
    
    For Each ctl In Me.Controls
        If ctl.Tag = "Something1" Then
            'Do something
        ElseIf ctl.Tag = "Something2" Then
            'Do something else
        End If
    Next ctl

 
Something else, you could create your own collection of controls, then add the existing controls in the order you want.
Code:
  'Module level variable to hold the control collection
  Private colControls As New Collection

  Private Sub Form_Load()
    'Add controls to the collection in the order you want
    colControls.Add Me.Controls(4)
    colControls.Add Me.Controls(2)
    colControls.Add Me.Controls(8)
  End Sub

  Private Sub DoSomething()
    Dim ctl As Control

    'This will process control 4, then 2, then 8
    For Each ctl In colControls
      'Do whatever
    Next ctl

  End Sub


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top