Question : more than 3 conditions for conditional formatting

In a form under called "To Call" I would like to apply more than 3 conditions for conditional formatting to the TextBox Field "DueDays".

Here are the background colours for the different DueDays values:

0 - Light Turquoise
1 - Bright Green
2 - Yellow
3 - Light Orange
>4 - Red

The Form is in DataSheet view.
Is there a VBA code to set the background colour according to TextBox value?

Answer : more than 3 conditions for conditional formatting

Is this a continuous form?  If so, you are out of luck.  

However, if it is a single form, you could call a function in the Form_Current and in the textboxs AfterUpdate events that will do this.  Something like the following.  You will need to substitute the values of x, y, and z in the rgb function to correspond to the exact color code you want to use.  You can figure this out by selecting the control in design view, opening the color dialog assigned to the backcolor property, then clicking the advance tab.  You will see the Red, Green and Blue values at the bottom of the dialog.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
Public Sub DueDaysColor

    Select Case me.txt_DueDays
        Case 0
            me.txt_DueDays.Backcolor = rgb(x, y, z) 'turquoise
        Case 1
            me.txt_DueDays.Backcolor = rgb(x, y, z) 'bright green
        Case 2
            me.txt_DueDays.Backcolor = rgb(x, y, z) 'yellow
        Case 3
            me.txt_DueDays.Backcolor = rgb(x, y, z) 'light orange
        Case >4
            me.txt_DueDays.Backcolor = rgb(x, y, z) 'red
        case else
            me.txt_DueDays.Backcolor = rgb(255, 255, 255) 'white
    end select

End sub


           
         
Random Solutions  
 
programming4us programming4us