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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting colors in ListView Control 1

Status
Not open for further replies.

mrdod

Technical User
Jun 12, 2006
103
US
Thanks to the people at tek-tips I got my information into a ListView Control. Now I was woondering how I can format the color to red of the entire row when the a subitem meets certain criteria. Below is the code I'm using. I see some posts on this subject and if I missed the answer just post the link. Any help would be great.

Option Compare Database

Public Sub FillEmployees()
On Error GoTo ErrorHandler
'Set Reference to Microsoft DAO 3.xx Library.

'set variables
Dim rs As DAO.Recordset
Dim db As Database
Dim lstItem As ListItem
Dim strSQL As String

Set db = CurrentDb()
strSQL = "SELECT * FROM tblhistory"
Set rs = db.OpenRecordset(strSQL)

With Me.lview
'Set ListView style
.View = lvwReport
'This is not supported by ListView 5
.GridLines = False
.FullRowSelect = True
'Clear Header and ListItems
.ListItems.Clear
.ColumnHeaders.Clear
End With
'Set up column headers
With Me.lview.ColumnHeaders
.Add , , "Mycounter", 0, lvwColumnLeft
.Add , , "Audit Number", 700, lvwColumnLeft
.Add , , "Status", 2000, lvwColumnLeft
.Add , , "Date Audited", 2000, lvwColumnLeft
.Add , , "Area Audited", 1500, lvwColumnRight
End With
' Add items and subitems to list control.

rs.MoveFirst
Do Until rs.EOF
Set lstItem = Me.lview.ListItems.Add()
lstItem.Text = Nz(rs!Mycounter)
lstItem.SubItems(1) = Nz(rs![Audit Number])
lstItem.SubItems(2) = Nz(rs![Status])
If Nz(rs![Status]) = "New" Then
'Put my code here?
Else: End If
lstItem.SubItems(3) = Nz(rs![Date Audited])
lstItem.SubItems(4) = Nz(rs![Area Audited])
'Next row
rs.MoveNext
Loop
'close recordset
rs.Close
Set rs = Nothing
DoCmd.Echo True


ErrorHandlerExit:
Exit Sub
ErrorHandler:
If Err = 3021 Then ' no current record
Resume Next
Else
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerExit
End If

End Sub

Thanks.
 
Have a look in the FAQ area of this forum: faq702-6027

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I tried copying the code but it's skipping over my If statement even though it's true. I placed the code in a module. Does that matter?

Sub Edit_Font()


Dim Item As ListItem
Dim Counter As Long
Dim strstatus As String
' Set the variable to the ListItem.
For Counter = 1 To Form_frmgetobject.lview.ListItems.Count
Set Item = Form_frmgetobject.lview.ListItems.Item(Counter)
' Set the variable to the Freight
strstatus = Item.SubItems(2)

With Form_frmgetobject.lview
If strstatus > "New" Then
'strstatus does = True but it's skipping to the End If??????
.ListItems.Item(Counter).ForeColor = vbRed
.ListItems.Item(Counter).ListSubItems(1).ForeColor = vbRed
.ListItems.Item(Counter).ListSubItems(2).ForeColor = vbRed
.ListItems.Item(Counter).ListSubItems(3).ForeColor = vbRed
.ListItems.Item(Counter).ListSubItems(4).ForeColor = vbRed
End If
End With


Next Counter
Form_frmgetobject.lview.Refresh

End Sub

Thanks PH for helping
 
Perhaps replace this:
If strstatus > "New" Then
with this ?
If strstatus = "New" Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Yeah I thought I replied to this thread but I guess NOT. I saw that right after I posted it. I guess that's what happens when I look at it too long. Thanks for helping. Where do you get those FAQs? I try to search for the information but 90% of the time I come up dry.
 
Where do you get those FAQs
By clicking the FAQs button.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
LOL!! I know that. I was looking for List View and not ListView (w/o space). I do appreciate your patience and help.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top