Microsoft KB Archive/210321

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

Article ID: 210321

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q210321



This article applies to a Microsoft Access database (.mdb) and to 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:  Open the sample database Northwind.mdb. Create a new blank report based on the Employees table. Set the Width property of the report to 5 in. If the field list is not displayed, click Field List on the View menu to display it. Drag the Notes field from the field list to the detail section. Delete the label of the Notes text box by selecting the label and then pressing the DELETE key.</li>  Set the following properties of the Notes text box: <pre class="fixed_text">   Name: Notes ControlSource: Notes CanGrow: Yes CanShrink: Yes Left: 0.2 in   Top: 0.166 Width: 4.6042 in   Height: 0.166 in                    </li> Click on detail section of the report.</li> Set the Height property of the detail section to 0.5 in.</li>  Set the OnPrint property of the detail section to the following event procedure: 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 </li> On the Debug menu, click Compile Northwind to compile the code.</li> Close the module, and then preview the report. Note that the Notes field and the box that surrounds it expand and contract together.</li></ol>

<div class="references_section">