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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Indexing through all controls on a form 1

Status
Not open for further replies.

Dilettant

Technical User
Sep 27, 2006
16
US
Can the tab index of controls on a form be used for indexing? For example copying the values of all controls into an array by using a for...next loop with a statement like
varrArray(I)=me.controls(I)

If not how can you move focus from one control to the next in order of the tab index?

Thanks for any help
 
Code:
varrArray(I)=me.controls(I)
is not making an array from the TabIndex. The value of I is the index of the control in the Controls collection.

Code:
Dim TextControlValues() As String
Dim var
On Error Resume Next
For var = 0 To Me.Controls.Count
    If TypeOf Me.Controls(var) Is TextBox Then
        ReDim Preserve TextControlValues(var)
        TextControlValues(var) = Me.Controls(var).Text
    End If
Next
will make an string array of the values of all textboxes on a userform.
If not how can you move focus from one control to the next in order of the tab index?
Move by WHAT event? The TabIndex is strictly for using Tab, or Shift-Tab. It is a property, not a method, within code. You SetFocus using the index of the control, not the TabIndex.


Of course you COULD set focus by looping through the controls and determining the TabIndex, and then using logic to set the focus. However, this seems very unwieldy. There is no direct connection between a control index -Me.Controls(i) - and Me.Controls(i).TabIndex. For example:
Code:
MsgBox Me.Controls(4).Name & "   " & Me.Controls(4).TabIndex
could return (and it does on my userform) "CommandButton2" - which has a control index = 4 - "0", as it has its TabIndex = 0.

TabIndex is a property, not a method.

Gerry
My paintings and sculpture
 
Oh, and as this was really a VBA question, it should be posted in the VBA forum. If you want to follow it further please post there. Thanks.

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top