Microsoft KB Archive/292943

= ACC2000: How to Implement CanGrow Functionality on a Data Access Page =

Article ID: 292943

Article Last Modified on 6/28/2004

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q292943



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

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



SUMMARY
When you set the CanGrow property of a section or a control on a report, Access adjusts the height of the section or the control to fit the data contained in it. This article shows you how to use VBScript to implement similar functionality on a data access page.



MORE INFORMATION
CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

In order to simulate CanGrow functionality, the control that you want to resize must be a BoundHTML control. This is because a text box control on a page uses the HTML  tag, which only support the hidden attribute of the Overflow property, whereas the BoundHTML control uses an HTML  tag, which support all attributes of the Overflow property.  Start Microsoft Access and open the sample database Northwind.mdb. Click Pages under Objects, and then click New. Click the arrow in the Choose table or query where the object's data comes from box, click Employees in the list, and then click OK. If a property sheet is not visible, click Properties on the View menu to display a property sheet. On the Edit menu, click Select Page to ensure that you are viewing the property sheet for the page.</li> Click the Data tab, and then change the DefaultControlType property of the page to Bound HTML.</li> Drag the LastName, FirstName, and Notes fields from the field list to the page. Position the fields beside one another horizontally and under the Header: Employees bar.</li> Reduce the height of the Header: Employees section to the height of the controls.</li> On the View menu, click Sorting and Grouping.</li> Change the RecordNavigationSection property to No.</li> Change the DataPageSize property to All.</li> Click in the Notes field.</li> If a property sheet is not visible, click Properties on the View menu.</li> In the property sheet, click the Format tab, and then change the Overflow property of the Notes field to visible.</li> On the Tools menu, point to Macro, and then click Microsoft Script Editor.</li> On the View menu, point to Other Windows, and then click Script Outline.</li> Expand Client Objects & Events.</li> Expand the MSODSC object, and then double-click the DataPageComplete event.IMPORTANT: When you create VBScript blocks for MSODSC events, you must add a parameter to the event name as follows:

<SCRIPT LANGUAGE=vbscript FOR=MSODSC EVENT=Current(oEventInfo)>

The <I>oEventInfo</I> parameter returns specific information about the event to the script. You must add this parameter, whether or not it will be used, because the script will not work without it.

</li>  Type or paste the following code between the SCRIPT tags: Dim c Dim sect Dim elem Set c = MSODSC.Constants Set sect = oEventInfo.DataPage.FirstSection While(Not(sect is Nothing)) If (sect.Type = c.sectTypeHeader) Then Set elem = sect.HTMLContainer.children(&quot;Notes&quot;) sect.HTMLContainer.style.height = elem.offsetTop + elem.offsetHeight + 5 End If   Set sect = sect.NextSibling Wend </li> Close the Script Editor, and then save the page in Microsoft Access. View the page in Microsoft Access and note that the height of the section is different for each record according to the height of the Notes field.</li></ol>

<div class="references_section">