ACC: Print Blank Line Every Nth Line in a Report (95/97)

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

SUMMARY

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

This article describes how to add blank lines between the printed lines on a report. You can use this method to add a blank line after a set number of lines. For example, you could use this method to add a blank line after every five lines of data in your report.

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

CAUTION: Following the steps in this example will modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and perform these steps on a copy of the database.

To add a blank line after every five lines in a report, follow these steps:

  1. Open the sample database Northwind.mdb and create a new report based on the Employees table.

  2. In the New Report dialog box, click Report Wizards, click the Employees Table, and then click OK.

  3. In the Available Fields box, select EmployeeID, and then click the ">" button. Repeat this step for the LastName, FirstName, and BirthDate fields, and then click Next.

  4. Select BirthDate as the primary group level, click the ">" button, and then click Next.

  5. Select LastName as the field to establish sort order in Field 1, and then click Next.

  6. In the "How would you like to Lay out your Report?" dialog box, click Next.

  7. In the "What Style would you like?" dialog box, click Next.

  8. In the "What Title would you like for your Report?" dialog box, type Employee Birthdays, and then click Finish.

  9. View the new report in Design view.

  10. On the View menu, click Code.

  11. Type the following lines in the module's Declarations section:

    Option Compare Database ' This code declares the cLines variable as an integer, and the ' cMaxLine constant as five. You can set the cMaxLine constant ' to insert a blank line after as many lines as you want. For ' example, to add a blank line after every eight lines in the ' report, set cMaxLine=8. Dim cLines As Integer Const cMaxLine=5

  12. In the Object box of the code module, select Report. In the Procedure box of the code module, select Open. Type the following procedure:

    Private Sub Report_Open (Cancel As Integer)

              'This code initializes the cLines variable to zero.
              cLines = 0
           End Sub
    
    

  13. In the Object box, select Detail. The Procedure box will change to Format. Type the following procedure:

    Private Sub Detail_Format (Cancel As Integer, FormatCount As _

                  Integer)
           ' This code adds a blank line by setting the NextRecord and
           ' PrintSection properties.
             If cLines Mod (cMaxLine+1) = 0 Then
                Me.NextRecord = False
                Me.PrintSection = False
             End If
             cLines = cLines + 1
           End Sub
    
    

  14. Close the module, and then preview the report. Note that there is a blank line in the report after every five lines of detail.

REFERENCES

For more information about the NextRecord or PrintSection properties, search for "NextRecord," and then "NextRecord property" using the Microsoft Access 97 Help Index.

Keywords          : RptLayou kbusage
Version           : 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.