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
- 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.
- OrderID
- OrderDate
- ShipName
- 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 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>
- 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 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>
- 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.
Additional query words:
subpage hide show
Keywords : AccDAP DAPScriptHowTo dtavbscript
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto
|