This article was previously published under Q170838
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Advanced: Requires expert coding, interoperability, and multiuser skills.
The detail section of a report can grow and shrink vertically if you setits CanGrow and CanShrink properties to Yes. However, line controls do nothave 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 thatcan grow and shrink as the detail section does.
This article assumes that you are familiar with Visual Basic forApplications and with creating Microsoft Access applications using theprogramming tools provided with Microsoft Access. For more informationabout 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 MicrosoftAccess version 2.0. For more information about Access Basic, please referto the "Building Applications" manual.
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 theend point of the line. The X1 and X2 arguments for a vertical line alwayshave the same value, because these arguments specify how far from the leftmargin the line is printed. However, the values of the Y1 and Y2 argumentsof a vertical line differ, and that difference specifies the height of theline.
Because a report's detail section can grow or shrink to varying sizes, youcan set the Y2 argument to a value that is greater than the expectedmaximum height of the detail section. Thus, the line is never shorter thanthe height of the detail section.
NOTE: Microsoft Access has a limitation of 22 inches for the height of acontrol or section. You will receive an overflow error if you try to setthe Y2 argument to a value greater than 22 inches. If your detail sectiongrows in excess of 22 inches, Microsoft Access will not be able to draw theline for the remainder of the section.
The following steps demonstrate how to use the Line method toprogrammatically draw a line in a report's detail section and makeit the same height as the section.
Open the sample database Northwind.mdb (or NWIND.MDB in version 2.0) and create a blank new report based on the Employees table.
Set the report's Width property to 5 in.
On the View menu, click Sorting And Grouping. Enter the following in the Sorting And Grouping window, and then close it:
Field/Expression: EmployeeID (Or Employee ID in Microsoft Access 2.0) Sort Order: Ascending Group Header: Yes
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 report's detail section.
Delete the label of the Notes text box by selecting the label, and then pressing the DELETE key.
Set the properties of Notes text box 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
Select the horizontal Detail bar to select the detail section of the report. Set the following properties for the detail section:
CanGrow: Yes CanShrink: Yes Height: 0.5 in.
Set the detail section's OnPrint property 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 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 = 8 ' Width of the line (in pixels). Note: Some printers do not accept odd numbers. 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
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.
For more information about using the Line method in reports, search theHelp Index for "Line method."
For more information about using the Line method to draw rectangles, click the following article number to view the article in the Microsoft Knowledge Base:
124642 How to shrink and grow a rectangle in a report