Avoid multiple select constructs

  • Thread starter Thread starter azSuch
  • Start date Start date
A

azSuch

Hi,
I m a newbie, I have this select case checking for textbox values. I
want to loop this so that it checks for all the textboxes. Or else I
got to write the same code for each Textbox :(

Select Case Me.TextBox1.Value

Case Is < 2
Me.TextBox1.BackColor = &H80FF80

Case 2 To 4
Me.TextBox1.BackColor = &H80FFFF

Case Is > 4
Me.TextBox1.BackColor = &HFF
End Select
 
For i = 1 To 10 'or whatver max value

Select Case Me.Controls("TextBox" & i).Value

Case Is < 2
Me.Controls("TextBox" & i).BackColor = &H80FF80

Case 2 To 4
Me.Controls("TextBox" & i).BackColor = &H80FFFF

Case Is > 4
Me.Controls("TextBox" & i).BackColor = &HFF
End Select
Next i

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
Assuming the controls are the first things on the form or in the container
then you could use something like this...

Dim N As Integer

For N = 0 To 2
With Me.Controls(N)
Select Case .Value

Case Is < 2
.BackColor = &H80FF80

Case 2 To 4
.BackColor = &H80FFFF

Case Is > 4
.BackColor = &HFF

End Select
End With
Next N

....if they're not then you'll need to change the values in the loop (in the
with block) as you go to point to the correct controls.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

User defined data type (losing its data) 2
Check date 2
[VBA] SUM RANGE OF VALUES 3
Need Help Modifying Code Please 3
Referencing a UserForm in a Module 2
referring to texbox 4
User-Defined Data TYPE 3
Looping 2

Back
Top