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

Change Background Color

Status
Not open for further replies.

miltie

Technical User
Nov 4, 2002
15
US
Hello all,

I searched through the different posts for a way to alternate the background color between records on a report. The code I used was this:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

Const cLightGrey = 12632256
Const cWhite = 16777215

If Me.Detail.BackColor = cWhite Then
Me.Detail.BackColor = cLightGrey
Else
Me.Detail.BackColor = cWhite
End If

end sub

It works great, but after looking at my report, I need it to alternate a different way. The database is a task list and the report shows each task a person is working on. Each person can be working on more than one task. I'd like the report to alternate the background color while grouped by the person's name.

Thanks for any help you can send my way.

Milt
 
The following will change colour for each person (first will be light grey, second will be white, etc). This assumes you have a numeric field in your data called UserID. The Static declaration means the variable maintains its value between calls - essentially the same as a report-level variable, but only has scope within the sub. Initially it will be zero, so will change on the first call (record).

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

Const cLightGrey = 12632256
Const cWhite = 16777215
Static LastUserID As Long

If Me.UserID <> LastUserID then
LastUserID = Me.UserID
If Me.Detail.BackColor = cWhite Then
Me.Detail.BackColor = cLightGrey
Else
Me.Detail.BackColor = cWhite
End If
End If

end sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top