ACC2000: How to Use a Command Button to Hide and Display a Frame

ID: Q232594


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

You can hide and display a frame by using a command button. This article shows you how to create script that hides and displays one frame within a frameset or an inline frame.


MORE INFORMATION

When you use frames to simulate a subform or subreport on a data access page, you may want to provide a command button that toggles whether the frame is visible or not.

For additional information about creating frames on a data access page, please see the following article in the Microsoft Knowledge Base:

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

Creating the Pages

  1. Open the sample database Northwind.mdb.


  2. Create a new page based on the Orders table and add the following fields from the Field List box to the page.



  3. Add a command button to the page with the following properties:


  4. 
       Command Button 
       ----------------------
       Id: cmdToggle
       Inner Text: Hide Frame 
  5. Save the page as dapOrdersFrameset.htm to a Web folder on the server.


  6. Make a copy of this page, name it dapOrdersIFrame, and save it as dapOrdersIFrame.htm to the same Web folder.


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


  8. Under the Order Details table in the Field List box expand Related Tables and add the ProductName field from the Products table to the page.


  9. 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 one, you can no longer update or add records on that page.


  10. Save the page as dapOrderDetails.htm to a Web folder on the server.


Frame Within a Frameset

  1. Create the following HTML page:


  2. 
    <HTML>
       <HEAD>
          <TITLE>Test Page</TITLE>
       </HEAD>
       <FRAMESET ID="FSet" ROWS="50%, 50%">
          <FRAME NAME="Top" SRC="dapOrdersFrameset.htm">
          <FRAME NAME="Bottom">
       </FRAMESET>
    </HTML> 
  3. Save the page as TestPage.htm in the same folder as dapOrdersFrameset.htm.


  4. Open the dapOrdersFrameset.htm page in Design view.


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


  6. Using the Script Outline, insert the following script for the Current event of the MSODSC:


  7. 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("Bottom").location = Loc
    -->
    </SCRIPT> 
  8. Using the Script Outline, insert the following script for the OnClick event of the cmdToggle button.


  9. 
    <SCRIPT language=vbscript for=cmdToggle event=onclick>
    <!--
    Dim myFSet
    
    Set myFSet = window.parent.document.all.item("FSet")
    
    If myFSet.rows = "50%, 50%" Then
       myFSet.rows = "100%"
       document.all.item("cmdToggle").innertext="Show Frame"
    Else
       myFSet.rows = "50%, 50%"
       document.all.item("cmdToggle").innertext="Hide Frame"
    End If
    -->
    </SCRIPT> 
  10. Open the TestPage.htm page with Microsoft Internet Explorer. Click the button several times. Note that clicking the command button toggles whether the lower frame is visible or not and that the text on the command button changes.


Inline Frame

  1. Open the dapOrdersIFrame page in Design view.


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


  3. Add an inline frame tag to the dapOrdersIFrame.htm page, immediately before the closing BODY tag (</BODY>).


  4. 
    <IFRAME ID="IFrm" HEIGHT="50%" WIDTH="80%"></IFRAME> 
  5. Using the Script Outline, insert the following script for the Current event of the MSODSC.


  6. 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> 
  7. Using the Script Outline, insert the following script for the OnClick event of the cmdTaggle button.


  8. 
    <SCRIPT language=vbscript for=cmdToggle event=onclick>
    <!--
    Dim myIFrm
    
    Set myIFrm = document.all.item("IFrm")
    
    If myIFrm.style.visibility = "" Then
       myIFrm.style.visibility = "hidden"
       document.all.item("cmdToggle").innertext="Show Frame"
    Else
       myIFrm.style.visibility = ""
       document.all.item("cmdToggle").innertext="Hide Frame"
    End If
    //-->
    </SCRIPT> 
  9. Open the page in Microsoft Internet Explorer. Click the command button several times. Note that clicking the command button toggles whether the inline frame is visible or not and that the text on the command button changes.


Additional query words: subpage hide show


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

Last Reviewed: July 13, 1999