Highlight Alternate Rows in Report (by date)

G

Guest

I use the code below to highlight alternate rows in most of my reports.
However, In one of my reports I would like to highlight groups of rows when
the date changes (i.e., all records for 01/01/05 are white, 01/03/05 would be
gray, 01/15/05 would be white, etc.). If the report name is 'Invoice' and
the date field is named 'tblwodDate', what would the code look like?

Private m_RowCount As Long
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
m_RowCount = m_RowCount + 1
If m_RowCount / 2 = CLng(m_RowCount / 2) Then
Me.Detail.BackColor = 15790320
Else
Me.Detail.BackColor = 16777215
End If
End Sub

Thanks!
 
M

[MVP] S.Clark

Assuming that the records are sorted such that none of the desired dates are
intermingled, you would use a variable to determine if the current value is
not the same as the previous value. If true then swap the color.

strCurrDate = fieldname
IF fieldname <> strCurrDate then
'React to a new grouping of data

'Set the flag to know what date to look for
strCurrDate = fieldname

'Swap the color
if intCurrColor = {white} then
intCurrColor = {Grey}
else
intCurrColor = {White}'There's a variable for colors, but can't
remember what it is.
endif

end if

'Apply the color
Me.Detail.BackColor = intCurrColor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top