Setting Back Colors
Posted on 2007-10-10
I have a tab control on a main form with one of the tabs as "Levels". On this tab are five combo boxes, one for each level and five text boxes where the user can type in a level description. The combo boxes contain colors as text (Red,Green,Yellow,Orange,White,None)
When the user selects a color, the backcolor of the combobox changes to the color selected. All works well. On the main form I have a matrix. (Grid of "cells" that is automatically populated) When the user clicks on one of the fields, it will start looping thru the colors (on each click). This is how they select the level colors for each part of the matrix.
The new requirement is that on click it only loops thru the colors they have defined on the Levels tab. For instance, if they only select "Red,Green,Yellow,None,None", then they want the click to only loop thru Red, green, yellow.
I'm trying to figure out the cleanest way to do this. I'm thinking of using a concatenated string as a variable with all of the colors, then checking that with Instr, but I don't know if I want to have to deal with removing the color if they change. Or I could loop thru the comboboxes and check the backcolors. Anyone have any ideas?
Here is my existing code. First the combobox backcolor change and then the click event for the cells.
' Changes back color of combobox based on user color selection
Dim i As Integer
i = Screen.ActiveControl.Tag
Select Case Screen.ActiveControl.Value
Case Is = "Green": Screen.ActiveControl.BackColor = vbGreen
Case Is = "Orange": Screen.ActiveControl.BackColor = RGB(255, 140, 0)
Case Is = "Yellow": Screen.ActiveControl.BackColor = vbYellow
Case Is = "Red": Screen.ActiveControl.BackColor = vbRed
Case Is = "White": Screen.ActiveControl.BackColor = vbWhite
Case Is = "None": Screen.ActiveControl.BackColor = vbWhite
Me.Controls("txtLevel" & i).SetFocus
' If a user clicks on a cell in the matrix that is not null
' this function will change the backcolor
' it loops thru the colors, changing to the next color
' each time they click
If IsNull(Screen.ActiveControl) Then
Screen.ActiveControl.BackColor = vbWhite
Select Case Screen.ActiveControl.BackColor
Case Is = vbWhite: Screen.ActiveControl.BackColor = vbRed
Case Is = vbRed: Screen.ActiveControl.BackColor = vbGreen
Case Is = vbGreen: Screen.ActiveControl.BackColor = RGB(255, 140, 0)
Case Is = RGB(255, 140, 0): Screen.ActiveControl.BackColor = vbYellow
Case Is = vbYellow: Screen.ActiveControl.BackColor = vbWhite
Me.Controls("txt" & Screen.ActiveControl.Tag).BackColor = _