Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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).

↑ Back to the top


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.

↑ Back to the top


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 <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.
  1. Start Microsoft Access and open the sample database Northwind.mdb.
  2. Click Pages under Objects, and then click New.
  3. 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.
  4. If a property sheet is not visible, click Properties on the View menu to display a property sheet.
  5. On the Edit menu, click Select Page to ensure that you are viewing the property sheet for the page.
  6. Click the Data tab, and then change the DefaultControlType property of the page to Bound HTML.
  7. 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.
  8. Reduce the height of the Header: Employees section to the height of the controls.
  9. On the View menu, click Sorting and Grouping.
  10. Change the RecordNavigationSection property to No.
  11. Change the DataPageSize property to All.
  12. Click in the Notes field.
  13. If a property sheet is not visible, click Properties on the View menu.
  14. In the property sheet, click the Format tab, and then change the Overflow property of the Notes field to visible.
  15. On the Tools menu, point to Macro, and then click Microsoft Script Editor.
  16. On the View menu, point to Other Windows, and then click Script Outline.
  17. Expand Client Objects & Events.
  18. 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.

  19. 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
     
    					
  20. 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.

↑ Back to the top


References

For more information about overflow and its attributes, click Microsoft Script Editor Help on the Help menu in the Script Editor, type overflow in the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB292943, kbdapscript, kbdap, kbhowto

↑ Back to the top

Article Info
Article ID : 292943
Revision : 2
Created on : 6/28/2004
Published on : 6/28/2004
Exists online : False
Views : 285