ACC2000: How to Simulate a Subform or Subreport on a Data Access Page

ID: Q232566


The information in this article applies to:

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

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


SUMMARY

This article shows you four methods that you can use to simulate a subform or 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 frameset, hyperlinks, inline frames, and groups.


MORE INFORMATION

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. 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. Create a new page based on the Orders table in Design view and add the following fields from the Field List box to the page:



  4. On the File menu, click Save.


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


  6. http://ServerName/FolderName/dapFrameset.htm
  7. Click Save.


  8. On the File menu, click Save As.


  9. In the Save As dialog box, type dapHyperlink and click OK.


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


  11. Repeat steps 7 through 9, but use dapIFrame instead of dapHyperlink.


  12. Create a new page based on the Order Details table in Design view and add the Quantity field from the Field List box to the page.


  13. Under the Order Details table, expand the Related Tables and add the ProductName field from the Products table.


  14. Open the Sorting and Grouping dialog box and set the Data Page Size for the Order Details group to 5.

    NOTE: Once you set the Data Page Size to a number greater than 1, you can no longer update or add records on that Page.


  15. On the File menu, click Save.


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


  17. http://ServerName/FolderName/dapOrderDetails.htm
  18. Click Save.


  19. 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 "Create Sample Pages" section.


  2. In the Database window, select the dapFrameset.htm page, and then click Design.


  3. On the Tools menu, point to Macro, and then click Microsoft Script Editor.


  4. Using the Script Outline, insert the following script:


  5. 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 oEventInfo parameter added above is used to return specific information about the event to the script. You must add this parameter, regardless of whether it will be used or not, because the script will fail without it.
    
    <SCRIPT LANGUAGE=vbscript FOR=MSODSC EVENT=Current(para)>
    <!--
    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> 
  6. On the File menu, click Save.


  7. On the File menu, click Exit.


  8. Using an HTML or text editor, create the following HTML page:


  9. 
    <HTML>
       <FRAMESET ROWS="50%, 50%">
          <FRAME ID="TopFrm" NAME="Top" SRC="dapFrameset.htm">
          <FRAME ID="BotFrm" NAME="Bottom">
       </FRAMESET>
    </HTML> 
  10. Save this file as OrdersFrameset.htm in the same folder on the Web server.

    NOTE: Because OrdersFrameset.htm contains a frameset, you cannot edit the page inside Access.


  11. 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 "Create Sample Pages" section.


  2. In the Database window, select the dapHyperlink.htm page, and then click Design.


  3. Select 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. In the Filter criteria for the data access page box, type OrderID=[OrderID], and then click OK.


  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 update the records. However, once you add the inline frame to the dapIFrame.htm page, you are unable to open the page directly from Access.
  1. Open the shared copy of Northwind.mdb that you created in step 1 of the "Create Sample Pages" section.


  2. In the Database window, select the dapIFrame page, and then click Design.


  3. On the Tools menu, point to Macro, and then click Microsoft Script Editor.


  4. Using the Script Outline, insert the following script:


  5. 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 oEventInfo parameter added above is used to return specific information about the event to the script. You must add this parameter, regardless of whether it will be used or not, because the script will fail without it.
    
    <SCRIPT LANGUAGE=vbscript FOR=MSODSC EVENT=Current(para)>
    <!--
    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> 
  6. On the File menu, click Save.


  7. Add the following HTML code just before the closing BODY tag.


  8. 
    <IFRAME ID="IFrm" HEIGHT=45% WIDTH=80%></IFRAME> 
    NOTE: You need to use a text or HTML editor to remove or comment this line before you can open the page from within Access.

  9. On the File menu, click Save.


  10. On the File menu, click Exit.


  11. Use Microsoft Internet Explorer to open the dapIFrame.htm page.


Using a Group

In this method, you create a grouped page. You can easily create this page by using the Page Wizard. However, you cannot update records on the page created with this method.
  1. Open the shared copy of the sample database Northwind.mdb.


  2. In the Database window, click Pages under Objects. Click New.


  3. In the New Data Access Page dialog box, click Page Wizard, and then click OK.


  4. 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. Click Next.


  5. Select OrderID in the list, and then click the > button to group the page by the OrderID field. Click Finish.


  6. You can 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.


  7. Open the Sorting and Grouping dialog box and select the OrdersWiz group from the list.


  8. Set the Data Page Size to 5.

    NOTE: Once you set the Data Page Size to a number greater than 1, you can no longer update or add records on that Page.


  9. On the File menu, click Save.


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


  11. http://ServerName/FolderName/dapGroup.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 (the plus "+" sign) to see the details of each order.


Additional query words: emulate mainpage main page subpage sub


Keywords          : AccDAP DAPHowTo DAPScriptHowTo dtavbscript 
Version           : WINDOWS:2000
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: July 12, 1999