ACC2: How to Print Blank Line Every Nth Line in a Report

ID: Q120842


The information in this article applies to:


SUMMARY

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

This article describes how you can 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.


MORE INFORMATION

The following example demonstrates how to add a blank line after every five lines in a report:

  1. Open the sample database NWIND.MDB and create a new report based on the Employees table. Choose the Report Wizards button, and then follow these steps:

    1. In the "Which Wizard do you want?" screen, select Tabular and then choose the OK button.


    2. In the Available Fields box, select Employee ID and then choose the ">" button. Repeat for Last Name, First Name, and Birth Date, and then choose the Next button.


    3. In the Available Fields box, select Birth Date and then choose the ">" button. Choose the Next button.


    4. In the "What style do you want for your report?" screen, choose the Next button.


    5. In the "What title do you want for your report?" screen, type Employee Birthdays, and then choose the Finish button.




  2. View the new report in Design view.


  3. From the View menu, choose Code.


  4. Enter the following code in the module:
    
          Option Compare Database
          Dim cLines As Integer
          Const cMaxLine=5 

    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.


  5. In the Object box on the toolbar, select Report. In the Procedure box on the toolbar, select Open. Enter the following code in the module:
    
          Sub Report_Open (Cancel As Integer)
             cLines = 0
          End Sub 

    This code initializes the cLines variable to zero.


  6. In the Object box, select Detail1. In the Procedure box, select Format. Enter the following code in the module:
    
          Sub Detail1_Format (Cancel As Integer, FormatCount As Integer)
             If cLines Mod (cMaxLine+1) = 0 Then
                Me.NextRecord = False
                Me.PrintSection = False
             End If
             cLines = cLines + 1
          End Sub 

    This code adds a blank line by setting the NextRecord and PrintSection properties.


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



REFERENCES

Microsoft Access "User's Guide," version 2.0, pages 677-680


Keywords          : kbusage RptLayou 
Version           : 2.0
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: April 7, 1999