Highlighting Alternate Rows In a Report

I have tried several different options for highlighting alternate rows in my reports.  I can't seem to make any stick.  Then, I came accross the following code on Microsofts site:
Option Compare Database
Option Explicit

Private shadeNextRow As Boolean
Const shadedColor = 12632256
' Const shadedColor = 15726583 ' alternative shade colors
' Const shadedColor = 14078404
' Const shadedColor = 13356495
' Const shadedColor = 14281974
Const normalColor = 16777215

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

  On Error GoTo Detail_Format_Error

' Choose a color based on the shadeNextRow value
  If shadeNextRow = True Then
    Me.Section(acDetail).BackColor = shadedColor
  Else
    Me.Section(acDetail).BackColor = normalColor
  End If

' Switch the color for the next row
  shadeNextRow = Not shadeNextRow
 
Detail_Format_Exit:
  Exit Sub

Detail_Format_Error:
  MsgBox "Error " & Err.Number & ": " & Err.Description
  Resume Detail_Format_Exit

End Sub

Problem is, with this code added, my report will NOT open in print preview, and after I try, I can no longer get into the design view of my report without either deleting the code or closing/reopening the database.   Any ideas on either making the code above work, or an alternative?


Thanks in Advance.
cebaker75Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cebaker75Author Commented:
Forgot Something-  The code I attached does work when the report is printed, but my reports need to open to print preview.  
0
RgGray3Commented:
One simple way is to use the record counter

you can use a number of schemes to alternate...  including  
If Me.detail.backcolor = vbwhite then
     Me.detail.backcolor=vbcyan
Else
     Me.detail.backcolor = vbwhite
End if


Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If Me.RecordCounter Mod 2 Then
        Me.Detail.BackColor = 14540253
    Else
        Me.Detail.BackColor = vbWhite
    End If
    
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cebaker75Author Commented:
Wow, that was so much easier and better.  Thank RgGray3!
0
RgGray3Commented:
Glad to be of assistance...

Sometimes things LOOK or SEEM more difficult than they really are...

Sometimes it takes more time to write 1 line of code than it does to write a page....

Always ask yourself ....   there has got to be a simple way to do this......  and often there is!

Good luck
0
RgGray3Commented:
BTW...  

Any release of the Ken Getz "Access Cookbook" books have Lots of these types of examples...
They are well structured and organized with sample databases to illustrate each concept...

Well worth the price of admission
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.