Loop through form objects

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

Hi,
I am looping through a forms objects in my code and
performing an action on each object of type textbox eg

For Each ctl In f.Controls
Select Case ctl.ControlType
Case acTextBox
ctl.BackColor = 4262909
Else
'Do nothing
End If

End Select
Next

This works fine but the order in which the action occurs
is different from the tab order of the objects on the
form. I don't know what order it loops in, perhaps the
order that the controls were originally added to the form,
but what I want to be able to do is to have this occur in
the same order as the controls appear on the form. Anyone
know how to do this?

Thanks in advance
Chris
 
Chris said:
I am looping through a forms objects in my code and
performing an action on each object of type textbox eg

For Each ctl In f.Controls
Select Case ctl.ControlType
Case acTextBox
ctl.BackColor = 4262909
Else
'Do nothing
End If

End Select
Next

This works fine but the order in which the action occurs
is different from the tab order of the objects on the
form. I don't know what order it loops in, perhaps the
order that the controls were originally added to the form,
but what I want to be able to do is to have this occur in
the same order as the controls appear on the form. Anyone
know how to do this?


No, the index of items in the Controls collection is
indeterminate. Sort of the order they were added, but with
several exceptions.

Besides, you're changing all of them, so what difference
does the order make??
 
Thanks Marshall,
I will have to go with plan B and put them
into an array and sort that, but it would have been easier
if there was a direct way to change the order in Access.

I do need to be able to do this. The code I posted is just
an example to show how I am looping through, it is not my
actual code.

The fields in my actual code change colour only if the
data entered into the field fails validation against a
regular expression. So it would be better if this occured
in tab order.

Thanks
Chris
 
Back
Top