Combo Box - change colours

K

Kuraige

I need to make the text in a combo box different colors, depending on the
status field I have - is there a way to do this

Thanks in advanced
 
S

Sprinks

Hi, Kuraige.

Sure. Change it via a Select Case statement and by changing the ForeColor
property. You will need to put this code in the form's OnCurrent event
procedure and the Status AfterUpdate event procedure:

Select Case Me!Status
Case firstcase
' Change to Red
Me!YourTextBoxName.ForeColor = 255
Case secondcase
' Change to Bright Green
Me!YourTextBoxName.ForeColor = 65280
Case thirdcase
' Another case
....
Case Else
' Put default color here
End Select

To determine the appropriate color codes, simply select a color in form
design view, and see how Access changes the ForeColor property.

HTH
Kevin Sprinkel
 
K

Kuraige

Great Idea

Thanks for the help

Sprinks said:
Hi, Kuraige.

Sure. Change it via a Select Case statement and by changing the ForeColor
property. You will need to put this code in the form's OnCurrent event
procedure and the Status AfterUpdate event procedure:

Select Case Me!Status
Case firstcase
' Change to Red
Me!YourTextBoxName.ForeColor = 255
Case secondcase
' Change to Bright Green
Me!YourTextBoxName.ForeColor = 65280
Case thirdcase
' Another case
....
Case Else
' Put default color here
End Select

To determine the appropriate color codes, simply select a color in form
design view, and see how Access changes the ForeColor property.

HTH
Kevin Sprinkel
 
K

Kuraige

Thanks guys

ths almost does what I need but I am not sure if this is possible or not -
but the code here will change all the list to the same color - is there a way
to display the color for that record that meets the requirements only and the
next record if the status is differnt display in a differnt color. all inside
the combo box

Thanks again guys
 
S

Sprinks

There's no way to give some of the rows in the combo box one color and others
another (that I know of, anyway--you may want to check Steve Lebans'
website), but the simple way is just to filter the combo box so that it
displays only those rows you want. You do this by changing the combo box'
Row Source property, in the same places where you're changing the forecolor:

Me!YourComboBox.RowSource = <sql statement>

For example, assuming you'd be filtering by the value of the status field,
and that the rows are in a table named Options, something like:

Me!YourComboBox.RowSource = "SELECT Options.ID, Options.Description FROM
Options WHERE Options.Status = Me!Status"

HTH
Sprinks
 
S

Sprinks

Forgot to mention--after changing the Row Source, you'll need to requery the
combo box:

Me!YourComboBox.Requery

Sprinks
 
Top