colors to alternate in rows (1 Viewer)

StefanSch

Registered User.
Local time
Today, 15:32
Joined
Jan 18, 2003
Messages
136
This message was once put in this Access Forum:

____________________________________________

Below is the code from the Microsoft Access 97 "Reports" sample db that alternates the color between rows within a report. You should be able to modify the code to use in a form.

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

Const WHITE = 16777215
Const YELLOW = 65535

If (Me![LineNum] Mod 2) = 0 Then
Me![ProductName].BackColor = YELLOW
Me![CategoryName].BackColor = YELLOW
Me![QuantityPerUnit].BackColor = YELLOW
Me![UnitsInStock].BackColor = YELLOW
Else
Me![ProductName].BackColor = WHITE
Me![CategoryName].BackColor = WHITE
Me![QuantityPerUnit].BackColor = WHITE
Me![UnitsInStock].BackColor = WHITE
End If

End Sub

HTH


ghudson

I am using Windows XP with Access 97

____________________________________________

Unfortunately, I could not get this to work. How do I add the text box [LineNum] in the report?

Stefan.
 

Mile-O

Back once again...
Local time
Today, 14:32
Joined
Dec 10, 2002
Messages
11,316
I'm guessing line num is added to your table as an autonumber field and that's why the MOD operator is used on it.
 
R

Rich

Guest
Add an unbound textbox to the detail section, hide it, set its control source to =-1, set the running sum to over all
 

StefanSch

Registered User.
Local time
Today, 15:32
Joined
Jan 18, 2003
Messages
136
Thanks Rich

The numbering works well.

However, the coloring is not working with the code below.

Did you get it to work?

Stefan
 

StefanSch

Registered User.
Local time
Today, 15:32
Joined
Jan 18, 2003
Messages
136
Yes, I re-named it. I don't get any error message but no rows are colored.
 

Fornatian

Dim Person
Local time
Today, 14:32
Joined
Sep 1, 2000
Messages
1,396
I use this:

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
Const Grey = 16777215
Const White = 12632256
Me.Detail.BackColor = IIf(Me.Detail.BackColor = White, Grey, White)
End Sub
 

Cosmos75

Registered User.
Local time
Today, 08:32
Joined
Apr 22, 2002
Messages
1,281
Wonderful! Simple and easy!

StephanSch & Fornation,

Nice examples!
:)
Rich said:
Add an unbound textbox to the detail section, hide it, set its control source to =-1, set the running sum to over all
Rich,
Thank you for adding that! Very clever of you!

I am not entirely sure I understand how this works but I have an idea.
Code:
Me.Detail.BackColor = IIf(Me.Detail.BackColor = White, Grey, White)
  1. On the 1st detail, there is no backcolor assigned (even if you have made the default backcolor yellow), so IIf returns White
  2. White is stored as the value for Me.Detail.Backcolor
  3. 1st detail's backcolor property is now equal to White.
  4. Code is run for 2nd detail
  5. The IIf's criteria will return TRUE (since Me.Detail.Backcolor = White from 1st detail), so Grey is returned & the .backcolor for the 2nd detail is Grey.
  6. and so on...

Is this what is going on?
:confused:
 
Last edited:

Users who are viewing this thread

Top Bottom