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

Alternating Shading between records 6

Status
Not open for further replies.

tbpcpa

Instructor
Oct 8, 2002
19
US
What is the best method if I want to alternate shading between records in a report?
 
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

    'Michael Red.   2/13/2002.      To 'Toggle the backolor, which
    'Provides alternate line shading
    Const XorToggle = 4144959

    Me.Detail.BackColor = Me.Detail.BackColor Xor XorToggle

End Sub
MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Michael

I've got a similar problem. I'm trying to get shading of report records when a condition is met. I used your code but added a simple IF statement:

[tt] 'Michael Red. 2/13/2002.
'To 'Toggle the backolor, which
'Provides alternate line shading

Const XorToggle = 4144959

If Me.Gap_Status = "Open" Then
Me.Detail.BackColor = Me.Detail.BackColor Xor XorToggle
End If[/tt]

The report has grouping and forced page-breaking after each group.

The result is that only some of the OPEN records are getting shaded. It's not consistent. Also, those that are shaded have the fields appearing in white boxes. I guess there's separate code to shade each field as well?

Any who, I'd appreciate your help with this, once again! Thanks in advance.

Jim DeGeorge [wavey]
 
Jim,

You don't want to "toggle" in this situation. Try this:
Code:
If Me.Gap_Status = "Open" Then
        Me.Detail.BackColor = 12632256
   Else: Me.Detail.BackColor = vbWhite
End If
For the white text boxes, set their BackStyle property to Transparent




A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
Douglas Adams
 

I like the use of

Const XorToggle = 4144959

Me.Detail.BackColor = Me.Detail.BackColor Xor XorToggle

but how do you work out the number to use for other colours ... like an even lighter grey, maybe a yellow or red?

I'm sure I worked it out before but no idea now!
 
A friend of mine came up with this code for alternate shading. Add the variable declaration for lngRowCount before your On Format event code. It should look something like this:
Code:
Option Compare Database
Option Explicit
Private lngRowCount As Long

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
lngRowCount = lngRowCount + 1
If lngRowCount / 2 = CLng(lngRowCount / 2) Then
   Me.Detail.BackColor = 65535    ' <--- change this color
Else
   Me.Detail.BackColor = 16777215 ' white
End If
End Sub
To find the correct integer value for the color I want, I like to refer to this web site: Look under the MSAccess column for the values.

Hoc nomen meum verum non est.
 
[srmclean,

To get the constant to use as the toggle, just XOR the colors you have selected.

If you want to generate your own specific shades to use, there are various (numerous) color functions to choose from, with RGB, perhaps being the most straighforward. It is at least addressed in the ubiquitous {F1} (a.k.a. Help) To use standard colors from the palette, you can select most any control (or form) and (temporarily) set one of it's color properties to the solor you want. moving the cursor off of the property will show the color value of the newly selected color. It is generally adviseable to return the color to it's original value after recording the color value (if you choose to use it).





MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Michael

I used your thread to alternate shading between records in a report. However i changed the &quot;Const XorToggle = 4144959&quot; to &quot;Const XorToggle = VBYellow&quot; and I get solid blue. Did i do somehting wrong or is it because i am still useing Access 97?
 
SATYR76,

Yes and no (respectively). You want the &quot;DIFFERENCE&quot; between the color values to display (on the basis of &quot;bits&quot;), not a COLOR. pleas review the following:

Code:
? vbwhite
 16777215 
? vbyellow
 65535
 
? vbWhite Xor vbYellow
 16711680 

? 16777215 xor 16711680
 65535 
? 65535 xor 16711680
 16777215

note that the FIRST use of XOR refers to the vb colors *white&quot; and &quot;yellow&quot;. This is the &quot;bit&quot; mask difference between the two values.

This value is the &quot;toggle&quot; constant, It is the second VALUE used in the other two XOR expressions. The second expression uses the value of &quot;white&quot; with the mask to return the value for yellow. The third expression then uses the results of the second (Yellow) with the toggle constant to return the result for &quot;White&quot;.





MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Thanks Michael,
I tired this and it worked like a charm.
Enjoy the star.
 
For some reason when I put the original code in VB, it highlights every other page. Where would I be going wrong with this?
 
Nevermind, I figured it out. It had to do with the groupings that I had.
 
>> " However i changed the "Const XorToggle = 4144959" to [highlight]"Const XorToggle = VBYellow"[/highlight] and I get solid blue. Did i do somehting wrong or is it because i am still useing Access 97? "

you are just one step off. To get any color you want just start with an XOR for your constant. For yellow try this:

[highlight #FF99FF]Const XorToggle = vbWhite Xor vbYellow[/highlight]​

just replace the vbYellow with other colors or numbers to get the color you are picking and not its "inverse" If you wanted to alternate between two colors, like vbYellow and a lighter yellow like "13041663", you could set the backgound to 13041663 and then use:

[highlight #FF99FF]Const XorToggle = 13041663 Xor vbYellow[/highlight]​

Just my two cents
AP
 
thanks Micheal, I was using Cosmo's code for quite a while, but now all the colors are "blocky"...you're code presented the color as smooth...go figure!

have a shooter!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top