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

ID: Q210321


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

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

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


SUMMARY

In a report, a text box can expand vertically if you set its CanGrow and CanShrink properties to Yes. Rectangles and lines, however, do not have these properties and cannot expand. To create a rectangle around a control that can grow or shrink, use the Line method to draw the rectangle.


MORE INFORMATION

The following example demonstrates how to use the Line method to draw a rectangle around a Memo field of variable size:

  1. Open the sample database Northwind.mdb.


  2. Create a new blank report based on the Employees table.


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


  4. If the field list is not displayed, click Field List on the View menu to display it.


  5. Drag the Notes field from the field list to the detail section.


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


  7. Set the following properties of the Notes text box:


  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. Click on detail section of the report.


  10. Set the Height property of the detail section to 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 Offset As Single
        Dim Color As Long
    
        'Specify unit of measurement for coordinates on a page.
        Me.ScaleMode = 1        'Twips (1440 twips = 1 inch).
    
        'Define an offset of 1/8 inch from the text box to the rectangle.
        Offset = 1440 / 8
    
        'X and Y coordinates for the top left corner of the box.
        X1 = Me![Notes].Left - Offset
        Y1 = Me![Notes].Top - Offset
    
        'X and Y coordinates for the bottom right corner of the box.
        X2 = Me![Notes].Left + Me![Notes].Width + Offset
        Y2 = Me![Notes].Top + Me![Notes].Height + Offset
    
        Me.DrawWidth = 3        'Width of the line (in pixels).
        
        Color = RGB(0, 0, 0)    'Use black line color.
    
        'Draw the rectangle with the Line method.
        Me.Line (X1, Y1)-(X2, Y2), Color, B
    End Sub 
  13. On the Debug menu, click Compile Northwind to compile the code.


  14. Close the module, and then preview the report. Note that the Notes field and the box that surrounds it expand and contract together.



REFERENCES

For more information about the Line Method, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type Line Method in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Additional query words: adjust can shrink grow

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


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