This article was previously published under Q114086
This article has been archived. It is offered "as is" and will no longer be updated.
Moderate: Requires basic macro, coding, and interoperability skills.
This article shows you how to shade every other detail line on a MicrosoftAccess report.
This article assumes that you are familiar with Visual Basic forApplications and with creating Microsoft Access applications using theprogramming tools provided with Microsoft Access. For more informationabout Visual Basic for Applications, please refer to your version ofthe "Building Applications with Microsoft Access" manual.
NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access versions 1.x and 2.0. For more information about Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x or the "Building Applications" manual in Microsoft Access version 2.0.
NOTE: This article explains a technique demonstrated in the samplefiles, RptSampl.exe (for Microsoft Access for Windows 95 version 7.0)and RptSmp97.exe (for Microsoft Access 97). For information about howto obtain these sample files, please see the following articles in theMicrosoft Knowledge Base:
145777ACC95: Microsoft Access Sample Reports Available in Download Center
175072ACC97: Microsoft Access 97 Sample Reports Available in Download Center
The following example uses an event procedure to alternate the backgroundcolor between white and yellow. On black and white printers, yellowtypically appears as light gray.
Open the sample database Northwind.mdb (or NWIND.MDB in versions 1.x and 2.0), and then open the Alphabetical List Of Products report in Design view.
Add a new text box control to the report's detail section and setthe following properties:
Name: LineNum ControlSource: =-1 RunningSum: Over All Visible: No
Note the equal sign in the ControlSource property setting.
Add the following code to the Print event of the detail section. Todo so, follow these steps:
With the properties box open, click the detail section header.
In the properties box, click the OnPrint property and click the Build button. Click Code Builder, and then click OK.
Enter the following code between the Sub and End Sub lines in the module:
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
NOTE: In Microsoft Access 1.x and 2.0, type spaces in the Product Name, Product ID, Category Name, Quantity Per Unit, and Units InStock field names.
On the Run menu, click Compile Loaded Modules to compile the event procedure code.
Close the report module.
Open the report in Design view, open the properties sheet for each control in the detail section, and verify that the BackStyle property is set to Normal.
Preview or print the report by clicking Print Preview or Print on the File menu. Note that every other detail line on the report is shaded to the extent that the line is covered with a text box.