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:
232566 ACC2000: How to Simulate a Subform or Subreport on a Data Access Page
Creating the Pages
- Open the sample database Northwind.mdb.
- Create a new page based on the Orders table and add the following fields from the Field List box to the page.
- Add a command button to the page with the following properties:
Command Button
----------------------
Id: cmdToggle
Inner Text: Hide Frame
- Save the page as dapOrdersFrameset.htm to a Web folder on the server.
- Make a copy of this page, name it dapOrdersIFrame, and save it as dapOrdersIFrame.htm to the same Web folder.
- Create a new page based on the Order Details table and add the Quantity field from the Field List box to the page.
- 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.
- 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. - Save the page as dapOrderDetails.htm to a Web folder on the server.
Frame Within a Frameset
- Create the following HTML page:
<HTML>
<HEAD>
<TITLE>Test Page</TITLE>
</HEAD>
<FRAMESET ID="FSet" ROWS="50%, 50%">
<FRAME NAME="Top" SRC="dapOrdersFrameset.htm">
<FRAME NAME="Bottom">
</FRAMESET>
</HTML>
- Save the page as TestPage.htm in the same folder as dapOrdersFrameset.htm.
- Open the dapOrdersFrameset.htm page in Design view.
- On the Tools menu, point to Macro, and then click Microsoft Script Editor.
- Using the Script Outline, insert the following script for the Current event of the MSODSC: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(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>
- Using the Script Outline, insert the following script for the OnClick event of the cmdToggle button.
<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>
- 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
- Open the dapOrdersIFrame page in Design view.
- On the Tools menu, point to Macro, and then click Microsoft Script Editor.
- Add an inline frame tag to the dapOrdersIFrame.htm page, immediately before the closing BODY tag (</BODY>).
<IFRAME ID="IFrm" HEIGHT="50%" WIDTH="80%"></IFRAME>
- Using the Script Outline, insert the following script for the Current event of the MSODSC.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(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>
- Using the Script Outline, insert the following script for the OnClick event of the cmdTaggle button.
<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>
- 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.