ACC2002: How to Graphically Display Percent of Total on a Report (304583)



The information in this article applies to:

  • Microsoft Access 2002

This article was previously published under Q304583
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 shows you how to use two rectangle controls to graphically display a progress-bar-style percent of total in a Microsoft Access report. This example uses a table with student grades and resizes a red rectangle during the Format event of the detail section of the report to graphically indicate the grade that the students achieved.

MORE INFORMATION

Create a New Database and a Table Named tblGrades

  1. Start Microsoft Access 2002.
  2. Create a new database named Progressbar.
  3. Create a new table named tblGrades with the following fields and properties:
       Table Name: tblGrades
       ----------------------------
       Field Name: id
       Data Type: AutoNumber
       Indexed: Yes (No Duplicates)
    
       Field Name: StudentName
       Data Type: Text
       Field Size: 50
    
       Field Name: Grade
       Date Type: Number
       Field Size: Byte
       Validation Rule: Between 0 and 100
    					
  4. Open the tblGrades table in Datasheet view.
  5. Enter the following records into the tblGrades table:
    idStudentNameGrade
    1Nancy Davolio90
    2Andrew Fuller75
    3Margaret Peacock100
    4Janet Leverling85
    5Steven Buchanan67
    6Michael Suyama45
    7Robert King95
    8Laura Callahan97
    9Anne Dodsworth0


  6. Close the table.

Create a Report That Will Graphically Display Student Grades

  1. Ensure that the Progressbar database is open.
  2. Click the tblGrades table, and then on the Insert menu, click Report.
  3. In the New Report dialog box, click AutoReport: Tabular, and then click OK.
  4. After the wizard finishes creating the report, click Design View on the View menu.
  5. Save the report as rptGrades.
  6. Click the Rectangle tool in the toolbox, and then draw a rectangle in the detail section of the report to the right of the Grade text box. Set the following properties for the rectangle control:
       
       Rectangle
       ----------------
       Name: GradeA
       Width: 2"
       Height: 0.2083"
    					
  7. Draw a second rectangle on top of the GradeA rectangle, and set the following properties:
       
       Rectangle
       ------------------
       Name: GradeB
       Width: 0.0417"
       Height: 0.1979"
       Back Style: Normal
       Back Color: 26367
    					
  8. Right-click the detail section of the report, and then click Properties.
  9. In the property sheet for the detail section of the report, set the OnFormat property to the following event procedure:
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
        Me!GradeB.Width = Me!GradeA.Width * (Me!Grade / 100)
    End Sub
    					
  10. On the File menu, click Close and Return to Microsoft Access.
  11. Save and then preview the report.
Note that the student grades are graphically displayed on the report.

Modification Type:MajorLast Reviewed:9/26/2003
Keywords:kbhowto KB304583