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
<TEXTAREA> tag, which only support the
hidden attribute of the
Overflow property, whereas the BoundHTML control uses an HTML
<SPAN> 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.
- Click the Data tab, and then change the DefaultControlType property of the page to Bound HTML.
- 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.
- Reduce the height of the Header: Employees section to the height of the controls.
- On the View menu, click Sorting and Grouping.
- Change the RecordNavigationSection property to No.
- Change the DataPageSize property to All.
- Click in the Notes field.
- If a property sheet is not visible, click Properties on the View menu.
- In the property sheet, click the Format tab, and then change the Overflow property of the Notes field to visible.
- On the Tools menu, point to Macro, and then click Microsoft Script Editor.
- On the View menu, point to Other Windows, and then click Script Outline.
- Expand Client Objects & Events.
- 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.
- 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("Notes")
sect.HTMLContainer.style.height = elem.offsetTop + elem.offsetHeight + 5
End If
Set sect = sect.NextSibling
Wend
- 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.