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

Loop through controls

Status
Not open for further replies.

bullyboy69

Technical User
Mar 12, 2003
9
GB
Majorly stuck here and wonder if anyone can help??

I'm trying to create a form. There are at least 20 textboxes on the form. I have a created a button to edit the record. What I would like to do is add some additional code so that when they press the button, the colour of the background changes in each text box. Rather than type in each textbox and tell it to change colour, is it possible to create a loop to find all the textboxes on the form and then change the colour??

Thanks to anyone that can help!!!
 
Try this . . .

Dim i As Integer

For i = 1 To Me.Controls.Count - 1
If TypeName(Me.Controls(i)) = "TextBox" Then
'Do your colour stuff here
End If
Next i

[elephant2]


The pen is mightier than the sword - and quite frankly . . easier to write with
 
or equally

Dim ctl as control

For Each ctl in Me.controls
If TypeName(Me.Controls(i)) = "TextBox" Then
'Do your colour stuff here
End If
Next ctl


 
or equally equal

Dim ctl as control

For Each ctl in Me.controls
If ctl.ControlType = acTextBox Then
me(ctl).BackColor = vbRed ' or whatever color you want
End If
Next ctl

PaulF
 
hmmmmmmmmmmm ... mmmmmmmmmmm ... mm

"like to" seems incomplete. Just as a start, recognize that once changed, they (with the brief snippets provided to date) they simply stay changed, so unless you are doming something else (complimentry) it (snippets shown) only work for the 'one shot'. Somewhere in the app / process you need to do more -other to have some at least consistient user interface. "Like to" gives little or no thought as to how to achieve hte remainder of the (from my perspective) necessary "other" code.




MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Thanks for the help. LIKE TO thank Michael in particular for his comments. Keep reading that dictionary toilet paper that you have.

LIKE TO give my kindest regards

Nicholas

You can't handle the truth
 
Michael (or anyone else) if you've got the time I would appreciate some help in thread702-620850
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top