ACC: How to Shade Every Other Detail Line on Reports

Last reviewed: October 24, 1997
Article ID: Q114086
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0, 7.0, 97

SUMMARY

Moderate: Requires basic macro, coding, and interoperability skills.

This article describes a method you can use to shade every other detail line on a Microsoft Access report.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "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 sample files, RptSampl.exe (for Microsoft Access for Windows 95 version 7.0) and RptSmp97.exe (for Microsoft Access 97). For information about how to obtain these sample files, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q145777
   TITLE     : ACC95: Microsoft Access Sample Reports Available on MSL

   ARTICLE-ID: Q175072
   TITLE     : ACC97: Microsoft Access 97 Sample Reports Available on MSL

MORE INFORMATION

The following example uses an event procedure to alternate the background color between white and yellow. On black and white printers, yellow typically appears as light gray.

  1. 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.

  2. Add a new text box control to the report's detail section and set the following properties:

          Name: LineNum
          ControlSource: =-1
          RunningSum: Over All
          Visible: No
    

    Note the equal sign in the ControlSource property setting.

  3. Add the following code to the Print event of the detail section. To do so, follow these steps:

        a. With the properties box open, click the detail section header.
    

        b. In the properties box, click the OnPrint property and click the
           Expression builder button. Click Code Builder, and then click OK.
    

        c. 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 in
          Stock fields.
    
        d. On the Run menu, click Compile Loaded Modules to compile
           the event procedure code.
    
        e. Close the report module.
    
    

  4. 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.


Additional query words: greenbar green bar
Keywords : kbusage RptLayou RptProp
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Hardware : x86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 24, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.