How to simulate a subform or a subreport on a data access page in Microsoft Access (291803)



The information in this article applies to:

  • Microsoft Office Access 2003
  • Microsoft Access 2002

This article was previously published under Q291803
Moderate: Requires basic macro, coding, and interoperability skills.

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

For a Microsoft Access 2000 version of this article, see 232566.

SUMMARY

This article demonstrates four methods that you can use to simulate a subform or a subreport on a data access page. There is no subpage control in the toolbox in Design view of a page. Therefore, these methods demonstrate how to imitate this behavior with a group, a frameset, hyperlinks, and inline frames.

MORE INFORMATION

Using a Group

In this method, you create a grouped page. You can easily create this page by using the Page Wizard; however, if you create the grouped page by using the wizard, the page will not be updateable. Alternatively, you can create a grouped page manually. If you create the grouped page manually, the page will be updateable in most cases.

Using the Page Wizard

  1. Place a copy of the sample database Northwind.mdb in a folder on the Web server or in a shared network folder.
  2. Open the copy of Northwind.mdb from the Web folder or network share.

    NOTE: Do not use a mapped drive letter unless everyone uses that same drive letter.
  3. In the Database window, click Pages under Objects, and then click New.
  4. In the New Data Access Page dialog box, click Page Wizard, and then click OK.
  5. Add the OrderID, ShipName, and OrderDate fields from the Orders table. Add the Quantity field from the Order Details table and the ProductName field from the Products table, and then click Next.
  6. Click OrderID in the list, and then click the > button to group the page by the OrderID field. Click Finish.
  7. Move the ShipName and OrderDate fields into the Header: Products-OrderID section to make the page look more like those in the other three methods.
  8. Right-click in the Header: OrdersWiz section, and then click Group Level Properties.
  9. Set the Data Page Size property to 5.
  10. On the File menu, click Save.
  11. In the Save As Data Access Page dialog box, click Web Folders under Save in. In the File name box, type the following:

    http://ServerName/FolderName/dapGroupWiz.htm

  12. Click Save.
  13. On the View menu, click Page View. You can also open the dapGroup.htm page with Microsoft Internet Explorer.
  14. Click the Expand control (+) to see the details of each order.

Creating the Page Manually

  1. Open the shared copy of Northwind.mdb that you created in step 1 of the "Using the Page Wizard" section.
  2. In the Database window, click Pages under Objects, and then click New. Do not select anything in the Choose the table or query where the object's data comes from box, and then click OK.
  3. In the toolbox, make sure that the Control Wizards are enabled.
  4. In the field list, double-click OrderID, ShipName, and OrderDate to add them to the page.
  5. In the field list, expand Related Tables, and then drag Order Details to the page beneath the Header: Orders section. Before releasing the mouse button, you should see a section added that says Create a new section below Orders.
  6. Click Tabular in the Layout Wizard, and then click OK.
  7. Right-click in the Header: Orders section, and then click Group Level Properties. Change the DataPageSize property to 1.
  8. On the File menu, click Save.
  9. In the Save As Data Access Page dialog box, click Web Folders under Save in. In the File name box, type the following:

    http://ServerName/FolderName/dapGroupWiz.htm

  10. Click Save.
  11. On the View menu, click Page View. You can also open the dapGroup.htm page with Microsoft Internet Explorer.
  12. Click the Expand control (+) to see the details of each order.

Create Sample Pages

Follow the steps in this section if you plan to use a frameset, a hyperlink, or inline frames. These steps create the sample main pages dapFrameset.htm, dapHyperlink.htm, and dapIFrame.htm. They also demonstrate how to create a dependent page, dapOrderDetails.htm, that you link to the main pages.
  1. Open the shared copy of Northwind.mdb that you created in step 1 of the "Using the Page Wizard" section.
  2. Create a new page in Design view that is based on the Orders table, and then add the following fields from the field list to the page:
    • OrderID
    • ShipName
    • OrderDate

  3. On the File menu, click Save.
  4. In the Save As Data Access Page dialog box, click Web Folders under Save in. In the File name box, type the following:

    http://ServerName/FolderName/dapFrameset.htm

  5. Click Save.
  6. On the File menu, click Save As.
  7. In the Save As dialog box, type dapHyperlink, and then click OK.
  8. In the Save As Data Access Page dialog box, make sure the Save in list is still pointing to FolderName on ServerName. In the File name box, type dapHyperlink.htm, and then click Save.
  9. Repeat steps 6 through 8, but use dapIFrame instead of dapHyperlink.
  10. Create a new page that is based on the Order Details table in Design view, and then add the Quantity field from the field list to the page.
  11. Under the Order Details table, expand Related Tables, and then add the ProductName field from the Products table.
  12. Right-click the page, and then click Group Level Properties. Set the DataPageSize property to 5.
  13. On the File menu, click Save.
  14. In the Save As Data Access Page dialog box, click Web Folders under Save in. In the File name box, type the following:

    http://ServerName/FolderName/dapOrderDetails.htm

  15. Click Save.
  16. Close any open pages.

Using a Frameset

In this method, you create an HTML file with a frameset that points to the dapFrameset.htm and dapOrderDetails.htm pages. This method provides the most flexibility by allowing you to see both pages at one time, to update the records in these pages, and to edit the design of these pages within Access.
  1. Open the shared copy of Northwind.mdb that you created in step 1 of the "Using the Page Wizard" section.
  2. In the Database window, click the dapFrameset.htm page, and then click Design.
  3. On the Tools menu, point to Macro, and then click Microsoft Script Editor.
  4. Click MSODSC in the Client Objects & Events box. Click Current in the Event box.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.
    <SCRIPT LANGUAGE=vbscript FOR=MSODSC EVENT=Current(oEventInfo)>
    <!--
    dim Loc
    dim Ser
    
    Loc = "http://<ServerName>/<FolderName>/dapOrderDetails.htm?serverfilter="
    Ser = chr(34) & "Orderid=" & orderid.value & chr(34)
    Loc = Loc & Ser
    
    window.parent.frames("BotFrm").location = Loc
    -->
    </SCRIPT>
    					
  5. On the File menu, click Save.
  6. On the File menu, click Exit to return to Access.
  7. Using an HTML or text editor, create the following HTML page:
    <HTML>
       <FRAMESET ROWS="50%, 50%">
          <FRAME ID="TopFrm" NAME="Top" SRC="dapFrameset.htm">
          <FRAME ID="BotFrm" NAME="Bottom">
       </FRAMESET>
    </HTML>
    					
  8. Save this file as OrdersFrameset.htm in the same folder on the Web server.
  9. Use Microsoft Internet Explorer to open OrdersFrameset.htm.

Using a Hyperlink

In this method, you create a hyperlink on the dapHyperlink.htm page that applies a filter before opening the dapOrderDetails.htm page. With this method, you can update records in both pages and modify the design of the pages. However, you cannot easily view both pages at the same time.
  1. Open the shared copy of Northwind.mdb that you created in step 1 of the "Using the Page Wizard" section.
  2. In the Database window, click the dapHyperlink.htm page, and then click Design.
  3. Click the Header: Orders section.
  4. On the Insert menu, click Hyperlink.
  5. In the Insert Hyperlink dialog box, click Page in This Database under Link to, and then click dapOrderDetails. In the Text to display box, type Show Details. Click the Server Filter button, and in the Filter criteria for the data access page box, type OrderID=[OrderID], and then click OK twice to close the Insert Hyperlink dialog box.
  6. On the File menu, click Save.
  7. On the View menu, click Page View. You can also open the dapHyperlink.htm page with Microsoft Internet Explorer.
  8. Click Show Details.

Using an Inline Frame

In this method, you modify the dapIFrame.htm page to include an inline frame that points to the dapOrderDetails.htm page. This method provides the flexibility of allowing you to see both pages at one time and to update the records.
  1. Open the shared copy of Northwind.mdb that you created in step 1 of the "Using the Page Wizard" section.
  2. In the Database window, click the dapIFrame page, and then click Design.
  3. On the Tools menu, point to Macro, and then click Microsoft Script Editor.
  4. Click MSODSC in the Client Objects & Events box. Click Current in the Event box.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.
    <SCRIPT LANGUAGE=vbscript FOR=MSODSC EVENT=Current(oEventInfo)>
    <!--
    dim Loc
    dim Ser
    
    Loc = "http://<ServerName>/<FolderName>/dapOrderDetails.htm?serverfilter="
    Ser = chr(34) & "Orderid=" & orderid.value & chr(34)
    Loc = Loc & Ser
    
    window.frames("IFrm").location = Loc
    -->
    </SCRIPT>
    					
  5. On the File menu, click Save.
  6. Add the following HTML code just before the closing BODY tag.
    <IFRAME ID="IFrm" HEIGHT=45% WIDTH=80%></IFRAME>
    					
  7. On the File menu, click Save.
  8. On the File menu, click Exit.
  9. Use Microsoft Internet Explorer to open the dapIFrame.htm page.

Modification Type:MinorLast Reviewed:9/27/2006
Keywords:kbProgramming kbScript kbDAPScript kbhowto KB291803 kbAudDeveloper