Color Code report - go through each row, compare with previous record, if different, highlighted all

R

richiecheng

Hi, I am working on a customize report. The datasource for the report
is filled by code. I am wondering if it's possible for me to
highlight rows with if one field of current record is different from
the previous record. The report is currently sorted in a specific
order.

Thanks for help!
 
A

Allen Browne

You can do this with code in the report's events.

1. Declare a variable in the General Declarations section of the report's
module (at the top, with the option statements.)

2. In the Print event procedure of the (Detail?) section, store the current
record's value to the variable.

3. In the Format event procedure of the same section, compare the current
record's value to the variable, and change the ForeColor/BackColor or
whatever you want formatted.
 
R

richiecheng

You can do this withcodein the report's events.

1. Declare a variable in the General Declarations section of the report's
module (at the top, with the option statements.)

2. In the Print event procedure of the (Detail?) section, store the current
record's value to the variable.

3. In the Format event procedure of the same section, compare the current
record's value to the variable, and change the ForeColor/BackColor or
whatever you want formatted.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.







- Show quoted text -

Sorry I wasn't able to get it working. Below is my code. Basically
it changed everything to blue, and I found out when it's run to
Sub_Detail_Format, the CurrentStyleNum is always "".

My question is, will this run Sub_Detail_Print and then
Sub_Detail_Format for each records, or it runs all the records for
Sub_Detail_Print and then run all the records for Sub_Detail_Format.


Thanks for your help,



Dim CurrentStyleNum As String
------------------------------------------


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

If [StyleNum] <> CurrentStyleNum Then

[StyleNum].ForeColor = vbBlue

End If


End Sub

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)

CurrentStyleNum = [StyleNum]

End Sub
 
A

Allen Browne

The code changes the ForeColor to Bule at the first record.

There's nothing there to change it to anything else.
Did you need an Else block?

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

You can do this withcodein the report's events.

1. Declare a variable in the General Declarations section of the report's
module (at the top, with the option statements.)

2. In the Print event procedure of the (Detail?) section, store the
current
record's value to the variable.

3. In the Format event procedure of the same section, compare the current
record's value to the variable, and change the ForeColor/BackColor or
whatever you want formatted.







- Show quoted text -

Sorry I wasn't able to get it working. Below is my code. Basically
it changed everything to blue, and I found out when it's run to
Sub_Detail_Format, the CurrentStyleNum is always "".

My question is, will this run Sub_Detail_Print and then
Sub_Detail_Format for each records, or it runs all the records for
Sub_Detail_Print and then run all the records for Sub_Detail_Format.


Thanks for your help,



Dim CurrentStyleNum As String
------------------------------------------


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

If [StyleNum] <> CurrentStyleNum Then

[StyleNum].ForeColor = vbBlue

End If


End Sub

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)

CurrentStyleNum = [StyleNum]

End Sub
 
R

richiecheng

The code changes the ForeColor to Bule at the first record.

There's nothing there to change it to anything else.
Did you need an Else block?

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.




Sorry I wasn't able to get it working. Below is my code. Basically
it changed everything to blue, and I found out when it's run to
Sub_Detail_Format, the CurrentStyleNum is always "".
My question is, will this run Sub_Detail_Print and then
Sub_Detail_Format for each records, or it runs all the records for
Sub_Detail_Print and then run all the records for Sub_Detail_Format.
Thanks for your help,
Dim CurrentStyleNum As String
------------------------------------------
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If [StyleNum] <> CurrentStyleNum Then
[StyleNum].ForeColor = vbBlue
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
CurrentStyleNum = [StyleNum]
End Sub- Hide quoted text -

- Show quoted text -

Great, it works!

Thank you very much.
 

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