Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox Forecolor

Status
Not open for further replies.

timb94

Programmer
Apr 20, 2004
58
US
I need to find out if this can be done.

I have a listbox on a form that has three columns, Line, Code and Status. The listbox is populated from a sql statement. When a row is selected a second set of text boxs is populated.

My code to populate the list box is as follows:
strsql = "SELECT line, code, status from mtable where id = 1"

me.lstCodes.RowSource = strsql
me.lstCodes.DefaultValue = 1

The above code results in the following being displayed in the listbox
Line Code Status
1 0100
2 0100 I
3 0200 U

There is no problem with the above code, however now they want any row that has anything in the status column (can be I, U or D) to be displayed in red.

I've searched the forums here and have done a Google search but cannot come up with anything.

If this is not possible, I'll tell them to just live with it.

Thanks for any assistance.
 
I don't think you can change the color of individual rows of a list box, but you could provide them with color in a combo box. In the AfterUpdate method, something like...
Code:
Private Sub YourComboBox_AfterUpdate()
   If Me.YourComboBox.Column(2) = "I" OR
         Me.YourComboBox.Column(2) = "U" OR
         Me.YourComboBox.Column(2) = "D" Then
      Me.YourComboBox.ForeColor = vbRed
   Else
      Me.YourComboBox.ForeColor = vbBlack
   End If


Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top