Microsoft KB Archive/207681

From BetaArchive Wiki
Knowledge Base


ACC2000: How to Print a Label After a Set Number of Lines of a Report

Article ID: 207681

Article Last Modified on 3/10/2003



APPLIES TO

  • Microsoft Access 2000 Standard Edition



This article was previously published under Q207681

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

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).


SUMMARY

This article describes how to display a label after a set number of printed lines of data on a report. For example, you can use this method to display a label after every third line of data in your report.

MORE INFORMATION

In order to display a label after every three lines in a report, follow these steps:

  1. Start Microsoft Access, and open the sample database Northwind.mdb or the sample project NorthwindCS.adp.
  2. In the Database window, click Reports under Objects, and then click New.
  3. In the New Report dialog box, click Report Wizard, select the Employees table from the list box indicating where the object's data comes from, and then click OK.
  4. Select one-by-one the EmployeeID, LastName, FirstName, and BirthDate fields from the Available Fields list by highlighting each field, and then clicking the > button. The selected fields will appear in the Selected Fields list.
  5. Click Finish.
  6. On the View menu, click Design View.
  7. Click the Detail bar to select the detail section of the report. On the View menu, click Properties.
  8. Click the Format tab, and then change the Height property to 0.75".
  9. Add a text box to the detail section of the report below the existing fields, and set the following properties:

    Name: txtCounter
    Control Source: =1
    Running Sum: Over All
    Visible: No

  10. Add another text box to the detail section, and set the following properties:

    Name: txtTextLabel
    Control Source: ="Any text you want on your label"
    Top: .25"
    Height: .45"
    Visible: No
    Can Shrink: Yes
    Can Grow: Yes

  11. Select only the label attached to the txtTextLabel text box, and then press DELETE. This prevents the text box label from appearing with the text box.
  12. Click the Detail bar to select the detail section of the report.
  13. In the Properties box, click the Event tab.
  14. Right-click the On Format box, and then on the shortcut menu, click Build. In the Choose Builder dialog box, click Code Builder, and then click OK.
  15. Type the following code:

    Private Sub Detail_Format (Cancel As Integer, _
          FormatCount As Integer)
       If ((Me![txtCounter]) Mod 3 = 0) Then
          Me![txtTextLabel].Visible = True
       Else
          Me![txtTextLabel].Visible = False
       End If
    End Sub
                        
  16. On the File menu, click Close and Return to the Microsoft Access.
  17. On the File menu, click Print Preview. Note that the label appears after every third record.


REFERENCES

For additional information about formatting reports based on a set number of lines per group, click the article numbers below to view the articles in the Microsoft Knowledge Base:

208696 ACC2000: How to Print a Blank Line Every Nth Line in a Report


For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:

212536 OFF2000: How to Run Sample Code from Knowledge Base Articles



Additional query words: inf printing have appear insert inserting

Keywords: kbhowto KB207681