I would like to ba able to shade every second line in a report to make reading easier…does anyone know if this can be done.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Shading alternate detail lines in a report (Access 2K)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Shading alternate detail lines in a report (Access 2K)
- This topic has 16 replies, 5 voices, and was last updated 22 years, 10 months ago.
AuthorTopicWScheryldi
AskWoody LoungerOctober 26, 2001 at 6:08 am #361981Viewing 0 reply threadsAuthorReplies-
WSJayden
AskWoody LoungerOctober 26, 2001 at 6:50 am #548737Hi
Yes this can be done!
You can use a little bit of VBA to do this.
I have included a sample access 2K file, with a table and report that shades every second line.
You use two events of the Report:
-the On Open event of the report
-the On Format of the detail section of the reportIn the On Open event of the report, set a module level variable to 0
The detail section of a report is ‘formatted’ once for each line of the report. This means that for every line of the report, we can make a bit of VBA run by using the ‘On Format’ event of the detail section of the report.
In the On Format event of the detail section, you need to:
-increment the Line Number variable by 1
-determine if the Line Number is odd or eventTo determine if the line number is odd or even the mod operator is used. The mod operator returns any remainder of the difference between the division of two numbers. For example, 3 mod 2 = 1 (because 3 / 2 = 1 with 1 remaining). If we divide by 2 and there are no remainders (ie. line number divide by 2 has no remainders) then the line is even, else it must be odd.
We then use a if..then..else..end if statement to change the background colour to grey if the number is odd, or white if the line number is even.
There you have it, a report with alternate grey and white lines!
Hope this helps. Unzip the file and run the Acc 2K database, run the report and you will see the result.
Here is the VBA from the Report Module
Option Compare Database
Option Explicit
‘Declare the line number variable and make it available to all
‘ withing the report
Private lngLineNumber As LongPrivate Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
‘===========================================================’
‘ Author: Jayden MacRae ‘
‘ Created: 26/10/2001 ‘
‘ Purpose: To increment the line number by one each time ‘
‘ and then to determine if the line number is ‘
‘ odd or even and set the background colour ‘
‘ appropriately or not. ‘
‘===========================================================’‘Increment line number by one
lngLineNumber = lngLineNumber + 1‘Determine if the current line number is a odd or even
‘ number
If lngLineNumber Mod 2 > 0 Then
Me.Detail.BackColor = 12632256
Else
Me.Detail.BackColor = 16777215
End If
End SubPrivate Sub Report_Open(Cancel As Integer)
‘Initially Set the Line Number Variable
lngLineNumber = 0
End SubCheers
Jayden
-
WSJayden
AskWoody LoungerOctober 26, 2001 at 6:57 am #548738I’ve just realised as an alternative, you can do it without the module level variable.
In this example, I’ve used the same technique, but instead, just checked to see if the current colour of the detail section is white. If it is white, then the colour is set to grey. If it isn’t white, then it is set to white.
Option Compare Database
Option ExplicitPrivate Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
‘===========================================================’
‘ Author: Jayden MacRae ‘
‘ Created: 26/10/2001 ‘
‘ Purpose: set the background colour appropriately or not. ‘ ‘
‘===========================================================’‘Determine if the current line number is a odd or even
‘ number
If Me.Detail.BackColor = 16777215 Then
Me.Detail.BackColor = 12632256
Else
Me.Detail.BackColor = 16777215
End If
End Sub -
WScheryldi
AskWoody Lounger -
WScharlotte
AskWoody LoungerOctober 26, 2001 at 12:04 pm #548771You can download a useful file from Microsoft called RptSmp00.exe, that contains a database of report samples, including one to shade every other line on a report. It has lots of other goodies in it as well, so I highly recommend getting it for reference.
-
WSCaesar3
AskWoody LoungerJune 12, 2002 at 3:36 pm #594181I read about this topic in Ms. Feddema’s “Inside Out” book (p. 295). I got the code to do the trick on-screen, but I don’t get the same results on paper. Matter of fact, on-screen my report header and page footer both appear as “light gray,” but they print out as plain-vanilla white. I don’t want my report header and page footer to print with light gray backgrounds, but I would like to see the alternate line shading in the detail section. What have I overlooked?
-
WSHansV
AskWoody LoungerJune 12, 2002 at 4:09 pm #594189Does the alternate shading of the detail section show on the screen, but not on the printout? You might have to make the dark color a bit darker, because many printers print light colors much lighter than they display on screen.
A mid grey, e.g. RGB(192,192,192) is a bit dark on my screen as background, but prints nicely. You can experiment with other values. -
WSCaesar3
AskWoody LoungerJune 12, 2002 at 7:12 pm #594282The “light gray” looks pretty dark on screen, but I can detect no trace of it on paper, not even the faintest hint. I was hoping the answer would be as embarrasingly simple as the one you gave me about fractions rounding up in boxes too small to display them. Well, I’m not at work right now, so this’ll have to wait till tomorrow. Thanks for the suggestion–I’ll check it out tomorrow morning!
-
WScharlotte
AskWoody Lounger -
WScharlotte
AskWoody Lounger -
WSCaesar3
AskWoody LoungerJune 13, 2002 at 10:57 am #594452I use an HP Deskjet 970 (color inkjet). The report I’m building in Access will replace a similar document we created years ago in Word. The Word table is autoformatted (“Contemporary”) for alternate line formatting, and said formatting prints just fine.
In fact, my Access report includes lines and rectangles set to print some shade of gray, and they print OK! Do I need to do something with the “on print” event procedure?
(For Helen:) This discussion brings up another question. The VBA code you provided in your book defines “vbLightGrey” as 12632256. Where does one find the “catalog” or whatever to get that string of eight digits to define specific colors? The More Colors dialog box displays numbers for Red/Green/Blue and for hue, saturation and luminescence, but…how does all that translate into that eight-digit number? I guess I need to understand this in order to change my code to specify yellow as the alternate-line shade.
And oh, by the way, what does “vb” (as in vbLightGrey) stand for? THANKS!
-
WSHansV
AskWoody LoungerJune 13, 2002 at 11:38 am #5944651. The code to alternate the background color should be in the OnPrint or OnFormat event of the Detail section (not in any of the headers or footers).
The controls in the detail section should have their background style set to transparent.
If you still have problems, can you post the code you’re using?2. Colors are defined by their RGB (Red/Green/Blue) values. Each can be 0 … 255 (hexadecimal 0 .. FF).
A color is stored as a long integer. The number representing a color is RedValue + 256 * (GreenValue + 256 * BlueValue).
For example:
Black has Red = 0, Green = 0, Blue = 0, so it is stored as 0 (hex 000000)
White has Red = 255, Green = 255, Blue = 255, so it is stored as 255 + 256 * (255 + 256 * 255) = 16,777,215 (hex 00FFFFFF).
Pure Green has Red = 0, Green = 255, Blue = 0, so it is stored as 0 + 256 * (255 + 256 * 0) = 65,280 (hex 0000FF00).
Cyan has Red = 0, Green = 255, Blue = 255, so it is stored as 0 + 256 * (255 + 256 * 255) = 16,776,960 (hex 00FFFF00).A light grey could be Red = 192, Green =192, Blue = 192, so it is stored as 192 + 256 * (192 + 256 * 192) = 12,632,256 (hex 00C0C0C0).
As you see, the hexadecimal notation is far more transparent than the decimal notation.
If you look up RGB in the help index, you’ll find more info.
3. Microsoft uses a naming convention for constants: the first two letters are always lower case and represent the application; the part after that starts with an upper case letter. Examples:
vbWhite: Visual Basic constant
acQuery: Access constant
xlCalculation: Excel constant
wdCharacter: Word constantIn VBA, there are 8 predefined constants for the basic colors, so you don’t need to know the numbers for these colors:
vbWhite, vbRed, vbGreen, vbBlue, vbCyan, vbMagenta, vbYellow and vbBlack.If a programmer wants to define another color constant, it is convenient to use the same prefix for consistency, like vbOrange. This is only a matter of consistency though, there is nothing to stop you from naming it conColorOrange or something like that.
-
WSCaesar3
AskWoody LoungerJune 13, 2002 at 12:46 pm #594492What a thorough response! (Where do you guys learn this stuff!?)
The formatting is in the Detail section. (On the property sheet for the Detail section: Event tab, On Format…). The code I’m using came straight outta Helen’s book (page 295, “Alternate Line Shading”). Thus:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Const vbLightGrey = 12632256If Me.CurrentRecord Mod 2 = 0 Then
Me.Section(acDetail).BackColor = vbLightGrey
Else
Me.Section(acDetail).BackColor = vbWhite
End IfEnd Sub
The formatting shows up on the screen exactly like I want it. Just doesn’t print!
Oh, yes: The controls in the Detail section all have their background set to transparent.
-
WSHansV
AskWoody LoungerJune 13, 2002 at 1:09 pm #594507I’m reduced to incoherent rambling…
I can’t see anything wrong with the code. I copied it straight out of your post into a report, and it printed as desired…
And since you mention that controls with a grey background are printed correctly, it seems not to be a printer setting.
When I check Data only in the Page Setup dialog, the alternating bands disappear from both the screen display and the printout.
What happens if you replace vbLightGrey by vbBlack? You should get horrible black bars.
-
WSCaesar3
AskWoody LoungerJune 13, 2002 at 4:30 pm #594599Yeah…”horrible black bars” is correct! But…they won’t print!
I tried changing the border properties of all my Detail rectangles and text boxes to transparent/color White, but to no avail.
So…next I’m gonna try printing this thing at a different system: Different computer, different printer, same OS.
Thanks for all your time and advice.
-
WSCaesar3
AskWoody LoungerJune 17, 2002 at 12:07 pm #595244 -
WSCaesar3
AskWoody LoungerJune 13, 2002 at 5:38 pm #594618OK, this isn’t the last word, but….
I tried printing this report on another system: Same make and model printer and same results. But then I used that second computer to print the report using an HP LaserJet 4. Results: the shading printed exactly as I wanted! The problem was the inkjet printer all along.
Sounds like I need to ask Hewlett Packard a question or two….
Thanks again!
-
-
-
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Uninstalr Updates
by
jv16
7 hours, 29 minutes ago -
Apple zero days for April
by
Susan Bradley
2 hours, 46 minutes ago -
CVE program gets last-minute funding from CISA – and maybe a new home
by
Nibbled To Death By Ducks
8 hours, 17 minutes ago -
Whistleblower describes DOGE IT dept rumpus at America’s labor watchdog
by
Nibbled To Death By Ducks
20 hours, 6 minutes ago -
Seeing BSOD’s on 24H2?
by
Susan Bradley
3 hours, 1 minute ago -
TUT For Private Llama LLM, Local Installation and Isolated from the Internet.
by
bbearren
10 hours, 30 minutes ago -
Upgrade from Windows 10 to 11
by
Holdsworth8
1 day, 4 hours ago -
Microsoft : AI-powered deception: Emerging fraud threats and countermeasures
by
Alex5723
1 day, 7 hours ago -
0patch
by
WSjcgc50
8 hours, 35 minutes ago -
Devices might encounter blue screen exception with the recent Windows updates
by
Susan Bradley
1 day ago -
Windows 11 Insider Preview Build 22631.5261 (23H2) released to Release Preview
by
joep517
1 day, 10 hours ago -
Problem opening image attachments
by
RobertG
1 day, 12 hours ago -
advice for setting up a new windows computer
by
routtco1001
2 days, 2 hours ago -
It’s Identity Theft Day!
by
Susan Bradley
1 day, 7 hours ago -
Android 15 require minimum 32GB of storage
by
Alex5723
2 days, 7 hours ago -
Mac Mini 2018, iPhone 6s 2015 Are Now Vintage
by
Alex5723
2 days, 7 hours ago -
Hertz says hackers stole customer credit card and driver’s license data
by
Alex5723
2 days, 8 hours ago -
Firefox became sluggish
by
Rick Corbett
43 minutes ago -
Windows 10 Build 19045.5794 (22H2) to Release Preview Channel
by
joep517
2 days, 12 hours ago -
Windows 11 Insider Preview Build 22635.5235 (23H2) released to BETA
by
joep517
2 days, 12 hours ago -
A Funny Thing Happened on the Way to the Forum
by
bbearren
1 day, 10 hours ago -
Download speeds only 0.3Mbps after 24H2 upgrade on WiFi and Ethernet
by
John
7 hours, 2 minutes ago -
T-Mobile 5G Wireless Internet
by
WSmmi16
1 day, 10 hours ago -
Clock missing above calendar in Windows 10
by
WSCape Sand
1 day, 11 hours ago -
Formula to Calculate Q1, Q2, Q3, or Q4 of the Year?
by
WSJon5
3 days, 3 hours ago -
The time has come for AI-generated art
by
Catherine Barrett
2 days, 7 hours ago -
Hackers are using two-factor authentication to infect you
by
B. Livingston
2 days, 17 hours ago -
23 and you
by
Max Stul Oppenheimer
3 days ago -
April’s deluge of patches
by
Susan Bradley
1 day, 4 hours ago -
Windows 11 Windows Updater question
by
Tex265
18 hours, 24 minutes ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.