PC Review


Reply
Thread Tools Rate Thread

Avoid multiple select constructs

 
 
azSuch
Guest
Posts: n/a
 
      23rd Apr 2008
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
 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      23rd Apr 2008
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)



"azSuch" <(E-Mail Removed)> wrote in message
news:686b0d74-3c57-47d9-a21a-(E-Mail Removed)...
> 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



 
Reply With Quote
 
James Snell
Guest
Posts: n/a
 
      23rd Apr 2008
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.


"azSuch" wrote:

> 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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How 2 avoid multiple IF's by LOOKUP's??? =?Utf-8?B?RkFSQVogUVVSRVNISQ==?= Microsoft Excel Misc 3 8th Jun 2007 09:01 AM
Asking for better logic to avoid multiple if's. Spy128Bit@gmail.com Microsoft Excel Programming 1 17th Jan 2007 02:50 PM
Sending from Multiple Account in Outlook (avoid multiple polls to server) Phil Jones Microsoft Outlook 3 15th Jun 2005 06:53 AM
Avoid sort on SELECT command _VJ Microsoft ADO .NET 21 28th May 2004 01:06 AM
If Select is the solution - how to avoid Select Stuart Microsoft Excel Programming 3 20th May 2004 09:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:38 PM.