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

Last reviewed: November 12, 1997
Article ID: Q124642
The information in this article applies to:
  • Microsoft Access versions 2.0, 7.0, 97

SUMMARY

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

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 may grow or shrink, you should draw the rectangle using the Line method.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access version 2.0. For more information about Access Basic, please refer to the "Building Applications" manual.

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 (or NWIND.MDB in version 2.0).

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

  3. Set the report's Width property to 5 in.

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

  5. Drag the Notes field from the field list to the report's detail
     section.

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

  7. Set the Notes text box's properties as follows:

        Name: Notes
        ControlSource: Notes
        CanGrow: Yes
        CanShrink: Yes
        Left: 0.2 in
        Top: 0.166
        Width: 4.6042 in
        Height: 0.166 in

  8. Select the horizontal Detail bar to select the detail section of the
     report. Set the detail section's Height property to 0.5 in.

  9. Set the detail section's OnPrint property to the following event
     procedure:

       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 ' ...in 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

 10. In Microsoft Access 2.0 only; type the following line in the
     module's Declarations section:

       Option Explicit

 11. On the Run menu, click Compile Loaded Modules to compile the code.

 12. 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, search for "Line Method," using the Microsoft Access 97 Help Index.


Additional query words: adjust can shrink grow
Keywords : kbusage RptOthr RptLayou
Version : 2.0 7.0 97
Platform : WINDOWS
Hardware : x86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 12, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.