different color for line in listbox (2 Viewers)

ingrid

Registered User.
Local time
Today, 09:30
Joined
Apr 10, 2003
Messages
42
I want to fill a listbox from a Recordset and define the color of the depending on a value from the Recordset.

Ik can only find how to change the color for the whole listbox. I'm thinking of something like this:

If status = "actual" Then
listbox.line1.forcolor = "red"
Else
listbox.line1.forcolor = "blue"
End If

I hope someone can help me.
 

Alex McDevitt

Registered User.
Local time
Today, 09:30
Joined
Nov 12, 2002
Messages
28
ingrid said:
I want to fill a listbox from a Recordset and define the color of the depending on a value from the Recordset.

Ik can only find how to change the color for the whole listbox. I'm thinking of something like this:

If status = "actual" Then
listbox.line1.forcolor = "red"
Else
listbox.line1.forcolor = "blue"
End If

I hope someone can help me.

The only way I know of doing this is to use a Continuous subform not a listbox.
With a subform, you can use conditional formating i.e. change colour on value. You can make a textbox to the size of the row, send the texbox to the back & set the conditional formating on this texbox. The only limit is that only 3 conditions can be made..
Hope this helps
 

namliam

The Mailman - AWF VIP
Local time
Today, 10:30
Joined
Aug 11, 2003
Messages
11,695
ingrid said:
Ik can only find how to change the color for the whole listbox.

That is the only thing there is in a default access listbox...

There may be some custom listboxes out there. Try starting your search at http://www.helenfeddema.com/

Regards & GL
 

ingrid

Registered User.
Local time
Today, 09:30
Joined
Apr 10, 2003
Messages
42
I tryed but I didn't find anything there. I did however find an example of a listbox which has different colors in each line. Only the color changes with the line. So line 1=red, lin2=blue etc. Also if you scroll.

I don't understand much of how it works but I'm gonna study it and try changing it so that it works the way I want it to.
 

namliam

The Mailman - AWF VIP
Local time
Today, 10:30
Joined
Aug 11, 2003
Messages
11,695
The default listbox is 1 thing and not seperat lines. Thus you cannot change the color of one line only.....

Regards
 

ShaunWillmott

Registered User.
Local time
Today, 09:30
Joined
Dec 21, 2001
Messages
17
Dear Ingrid,

If you are using Access 2000, you could try and use the ListView Control instead, this gives you the sort of functions you are looking for.

I used one recently to display messages to the user on a form and these message can be any definable colour, the Control was called ListMessages and the code to display the messages looked like this:

If DateSerial(Year(Date), Month(Me.dob), Day(Me.dob)) > Date Then
Days2Birthday = DateSerial(Year(Date), Month(Me.dob), Day(Me.dob)) - Date
Else
Days2Birthday = Date - DateSerial(Year(Date), Month(Me.dob), Day(Me.dob))
End If
Debug.Print "day 2 Birth "; Days2Birthday

Me.ListMessages.ListItems.Clear
Set mListItem = ListMessages.ListItems.Add()
With mListItem

.Text = "Birthday in " & Days2Birthday & " Days"
.SmallIcon = "Birthday"
If Days2Birthday < 15 Then
.Bold = True
.ForeColor = vbRed
End If
End With

First the code works out the number of days to the person's birthday, then the ListView is cleared.

Next the ListView is set to Add and the item (Line in the ListBox) is added with the attributes of .Text (The text of the line)
If the Birthday is 15 days away or less, then the Line is displayed as Bold and Red

Hope this helps

Regards

Shaun
 

ShaunWillmott

Registered User.
Local time
Today, 09:30
Joined
Dec 21, 2001
Messages
17
Dear Ingrid,

I know that Access 97 supports other ActiveX controls like TreeView, so it may also support ListView.

Check the toolbox in Form Design mode and click on more controls for a full list, my system (Access 2000) lists it as Microsoft ListView Control.

Also there are lots of examples of it's use on the Web

Good luck

Regards

Shaun
 

Users who are viewing this thread

Top Bottom