ACC2000: How to Set Multiple Sort Order Values on a Data Access Page
ID: Q234986
|
The information in this article applies to:
Advanced: Requires expert coding, interoperability, and multiuser skills.
This article applies to a Microsoft Access database (.mdb) and a Microsoft Access project (.adp).
SUMMARY
This article shows you how to create an HTML page that sorts a data access page by three different fields. This HTML page is a frameset made up of two data access pages. The first page provides the controls to sort the second page.
MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty
either expressed or implied, including, but not limited to, the implied warranties of
merchantability and/or fitness for a particular purpose. This article assumes that you
are familiar with the programming language being demonstrated and the tools used to
create and debug procedures. Microsoft support professionals can help explain the functionality
of a particular procedure, but they will not modify these examples to provide added
functionality or construct procedures to meet your specific needs. If you have limited
programming experience, you may want to contact a Microsoft Certified Solution Provider
or the Microsoft fee-based consulting line at (800) 936-5200. For more information about
Microsoft Certified Solution Providers, please see the following page on the World Wide Web:
http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the
following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.asp
The following sections show you how to create an HTML page (Frameset Page) and two data access pages (Header Page and Detail Page) in the sample database Northwind.mdb.
Header Page
The Header page contains three dropdown list controls, six option buttons, and two command buttons that you use to control the sort order of the Detail page. The dropdown list controls allow you to choose which fields to sort by. The option buttons allow you to decide whether those fields are sorted in ascending or descending order. One command button sorts the Detail page and the other command button resets the dropdown lists, option buttons, and the sort order of the detail page.
- Open the sample database Northwind.mdb.
- Create the following table named tblSort:
Table: tblSort
-------------------
Field Name: SortFld
Data Type: Text
Table Properties: tblSort
-------------------------
PrimaryKey: SortFld
- Add the following records to the table:
City
CompanyName
ContactName
Country
CustomerID
Region
- Create the following page named dapSortHeader:
Command button
--------------
ID: cmdSort
Caption: Sort
Command button
--------------
ID: cmdClear
Caption: Clear
Dropdown list
-----------------------------
ID: SortList1
ListRowSource: Table: tblSort
ListDisplayField: SortFld
ListBoundField: SortFld
Dropdown list
------------------------------
ID: SortList2
ListRowSource: Table: tblSort
ListDisplayField: SortFld
ListBoundField: SortFld
Dropdown list
------------------------------
ID: SortList3
ListRowSource: Table: tblSort
ListDisplayField: SortFld
ListBoundField: SortFld
Option group
------------------------------
ID: Frame1
BorderStyle: none
Set the group legend's Visibility property to hidden.
Option button (inside Frame1)
------------------------------
ID: OptionAsc1
Set the InnerText property of the button's Label to Ascending.
Option button (inside Frame1)
------------------------------
ID: OptionDsc1
Set the InnerText property of the button's Label to Descending.
Option group
------------------------------
ID: Frame2
BorderStyle: none
Set the group legend's Visibility property to hidden.
Option button (inside Frame2)
------------------------------
ID: OptionAsc2
Set the InnerText property of the button's Label to Ascending.
Option button (inside Frame2)
------------------------------
ID: OptionDsc2
Set the InnerText property of the button's Label to Descending.
Option group
------------------------------
ID: Frame3
BorderStyle: none
Set the group legend's Visibility property to hidden.
Option button (inside Frame3)
------------------------------
ID: OptionAsc3
Set the InnerText property of the button's Label to Ascending.
Option button (inside Frame3)
------------------------------
ID: OptionDsc3
Set the InnerText property of the button's Label to Descending.
- On the Tools menu, point to Macro, and then click Microsoft Script Editor.
- On the HTML menu, point to Script Block, and then click Client.
- Type the following script:
<SCRIPT language=vbscript>
<!--
Public strSort
-->
</SCRIPT>
- Using the Script Outline, insert the following script for the onClick event of cmdSort:
<SCRIPT event=onclick for=cmdSort language=vbscript>
<!--
Dim i
strSort = ""
For i = 1 to 3
' Determine which dropdown lists contain field names.
If Document.All.Item("sortList" & i).Value <> "" Then
' Add the field names to the sort order sting.
strSort = strSort & Document.All.Item("sortList" & i).Value
If Document.All.Item("OptionDsc" & i).Checked = True Then
' Add the word "Desc" (to sort the field in descending order)
' and a list separator to the sort string.
strSort = strSort & " Desc, "
Else
' Add a list separator to the sort string. It will automatically
' sort the field in ascending order, however, you could include
' then word "Asc".
strSort = strSort & ", "
End if
End if
Next
' Remove the extra characters from the end of the sort string
If Right(strSort, 2) = ", " Then
strSort=Left(strSort, Len(strSort)-2)
End if
' Set the sort order for the Detail page.
Window.Parent.Frames("dtl").MSODSC.DataPages(0).Recordset.Sort=strSort
-->
</SCRIPT>
- Using the Script Outline, insert the following script for the onClick event of cmdClear:
<SCRIPT event=onclick for=cmdClear language=vbscript>
<!--
' Reset all the dropdown lists and option buttons.
For i = 1 to 3
Document.All.Item("SortList" & i).Value = ""
Document.All.Item("OptionAsc" & i).Checked = False
Document.All.Item("OptionDsc" & i).Checked = False
Next
' Clear the sort string
strSort = ""
' Set the sort order for the Detail page back to the default.
Window.Parent.Frames("dtl").MSODSC.DataPages(0).Recordset.Sort=strSort
-->
</SCRIPT>
Detail Page
The Detail page is the page that shows the records in the sort order specified by the Header page.
- Create the following page named dapSortDetail based on the Customers table:
Text box
-------------------------
ID: CustomerID
ControlSource: CustomerID
Text box
--------------------------
ID: CompanyName
ControlSource: CompanyName
Text box
--------------------------
ID: ContactName
ControlSource: ContactName
Text box
-------------------
ID: City
ControlSource: City
Text box
----------------------
ID: Country
ControlSource: Country
Text box
---------------------
ID: Region
ControlSource: Region
- On the Page Design toolbar, click Sorting and Grouping.
- Under Group Record Source, click Customers, and then set the CaptionSection property to Yes. Set the DataPageSize property to 10.
- Move the labels to the Caption section.
- Arrange all the text boxes and labels in a line near the top of the appropriate section. Decrease the size of section to remove extra blank space.
Frameset Page
The Frameset page is the HTML page that loads the two data access pages.
- Using an HTML or text editor, create the following HTML page and save it as SortFrame.htm in the same folder as the two data access pages:
<HTML>
<FRAMESET ROWS="18%, *">
<FRAME ID="hdr" SRC="dapSortHeader.htm">
<FRAME ID="dtl" SRC="dapSortDetail.htm">
</FRAMESET>
</HTML>
- Use Microsoft Internet Explorer to open the SortFrame.htm page.
Additional query words:
sorted sorting
Keywords : kbdta AccCon AccDAP DAPScriptHowTo dtavbscript
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto