Re: Iterate through controls
I think it's the order in which you placed the controls on the form at designtime (not the taborder).
Crazy D @ Work :-)
Re: Iterate through controls
It is not even that order. To start with, it may appear so (Reverse order of your control insertion); but after adding a few more controls the order is unpredictable. It appears to group all text boxes together ,all labels together etc.
But I could not find the exact logic.
Thanks for the reply.
Re: Iterate through controls
The control list is a linked list with no useful order. If you only have a few, you can organize them by hand:
dim oaControls(5) as control
private Sub Form_Load()
set oaControls(0)=Label1
set oaControls(1)=Text1
set oaControls(2)=Label2
set oaControls(3)=Text2
set oaControls(4)=Label3
End Sub
...sometime later...
' text for Textbox and Label must be accessed with diff properties
for i=0 to 4
if typeof oaControls(i) is Label then
whatIwant = oaControls(i).Caption
else
whatIwant = oaControls(i).Text
end if
next
You might consider making the labels into Textboxes with input disabled, to make coding access easier. You can create them as a control array, such as Text1(0) through Text1(n). These are very easy to work with by indexing.
Re: Iterate through controls
If you want to iterate through controls in accordance to their tab order it can easily be done as follows:
Sub GetControl (m_TabOrderNum as integer)
Dim objControl As Control
For Each objControl In Form1
If objControl.TabIndex = m_TabOrderNum Then
'do whatever, for example
objControl.SetFocus ' note that you cannot set focus to a label control
Exit For
End If
Next
End Sub
Sky1000