Microsoft KB Archive/124642

From BetaArchive Wiki
Knowledge Base


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

Article ID: 124642

Article Last Modified on 1/19/2007



APPLIES TO

  • Microsoft Access 2.0 Standard Edition
  • Microsoft Access 95 Standard Edition
  • Microsoft Access 97 Standard Edition



This article was previously published under Q124642

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

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 Width property of the report 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 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:

    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 Height property of the detail section to 0.5 in.
  9. Set the OnPrint property of the detail section 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 Declarations section of the module:

           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: kbhowto kbprogramming kbusage KB124642