ACC2000: How to Create a Line That Can Shrink and Grow in a Report

ID: Q197595


The information in this article applies to:
  • Microsoft Access 2000

Advanced: Requires expert coding, interoperability, and multiuser skills.


SUMMARY

The detail section of a report can grow and shrink vertically if you set its CanGrow and CanShrink properties to Yes. However, line controls do not have these properties and cannot grow or shrink as the detail section does. This article demonstrates how to use the Line method to draw a line that can grow and shrink as the detail section does.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp


MORE INFORMATION

The Line method accepts two sets of coordinates. The first set (X1,Y1) determines the top left position, which is the starting point of the line. The second set (X2,Y2) determines the bottom right position, which is the end point of the line. The X1 and X2 arguments for a vertical line always have the same value, because these arguments specify how far from the left margin the line is printed. However, the values of the Y1 and Y2 arguments of a vertical line differ, and that difference specifies the height of the line.

Because the detail section of a report can grow or shrink to varying sizes, you can set the Y2 argument to a value that is greater than the expected maximum height of the detail section. Thus, the line is never shorter than the height of the detail section.

NOTE: Microsoft Access has a limitation of 22 inches for the height of a control or section. You will receive an overflow error if you try to set the Y2 argument to a value greater than 22 inches. If your detail section grows in excess of 22 inches, Microsoft Access will not be able to draw the line for the remainder of the section.

The following steps demonstrate how to use the Line method to programmatically draw a line in the detail section of a report and make it the same height as the section.

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


  2. Set the Width property of the report to 5 in.


  3. On the View menu, click Sorting and Grouping. Enter the following in the Sorting and Grouping dialog box, and then close it:


  4. Field/Expression: EmployeeID
    Sort Order: Ascending
    Group Header: Yes
  5. If the field list is not displayed, click the Field List on the View menu to display it, and then drag the Notes field from the field list to the detail section of the report.


  6. Delete the label of the Notes text box by selecting the label, and then pressing the DELETE key.


  7. Set the properties of Notes text box as follows:


  8. Name: Notes
    ControlSource: Notes
    CanGrow: Yes
    CanShrink: Yes
    Left: 0.2 in
    Top: 0.166
    Width: 4.6042 in
    Height: 0.166 in
  9. Select the horizontal detail bar to select the detail section of the report. Set the following properties for the detail section:


  10. CanGrow: Yes
    CanShrink: Yes
    Height: 0.5 in.
  11. Set the OnPrint property of the detail section to the following event procedure:


  12. 
    Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
       Dim X1 As Single, Y1 As Single
       Dim X2 As Single, Y2 As Single
       Dim Color As Long
    
       ' Specify unit of measurement for coordinates on a page...
       Me.ScaleMode = 5 ' Specify that measurement occur in inches.
    
       ' Set line to print 5 inches from the left margin.
       X1 = 5
       X2 = 5
    
       ' Set line to print from the top of the detail section
       ' to a maximum height of 22 inches.
       Y1 = 0
       Y2 = 22
       Me.DrawWidth = 25 ' Width of the line (in pixels).
       Color = RGB(0, 0, 0)  ' Use black line color.
    
       ' Draw the line with the Line method.
       Me.Line (X1, Y1)-(X2, Y2), Color
    End Sub 
  13. Preview the report. Note that the height of the vertical line to the right of the Notes field is the same as the height of the detail section.



REFERENCES

For more information about the Line method, click Microsoft Access Help on the Help menu, type "Line method" in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

For more information about using the Line method to draw rectangles, please see the following article in the Microsoft Knowledge Base:

Q210321 ACC2000: How to Shrink and Grow a Rectangle in a Report

Additional query words: size

Keywords : kbdta AccCon RptLayou KbVBA
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: July 15, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.