ACC2000: How to Create a Top 10 List on a Data Access PageID: Q232593
|
This article describes how to create a Top 10 list on a data access page, that is, a page that lists the first 10 records based on the sort order. The example in this article shows how to create the page for both a Microsoft Access database and a Microsoft Access project.
In the following example, you first create a query or a view based on the "Sales by Category" query, and then the Top 10 data access page.
Query in Northwind.mdb (an Access database)
- In the Database window, click Queries under Objects, and then click New.
- Click Design View, and then click OK.
- Create the following query based on the "Sales by Category" query:
Query: qryTop10 --------------------------- Field: ProductName Total: Group By Field: CategoryName Total: Group By Field: Sales: ProductSales Total: Sum Sort: Descending
- Right-click an empty area in the query design grid, and then click Properties on the shortcut menu. Set the TopValues property to 10.
NOTE: You can use any number or percentage that you want. For example, you can set the TopValues property to 15%.- Close and save the query as TopTen.
View in NorthwindCS.adp (an Access project)
- In the Database window, click Views under Objects, and then click New.
- On the View menu, point to Show Panes, and then click SQL.
- Type the following SQL statement:
NOTE: You can use any number or percentage that you want. For example, you can type 15 PERCENT in the SQL statement.SELECT TOP 10 ProductName, CategoryName, SUM(ProductSales) AS Sales FROM [Sales By Category] GROUP BY CategoryName, ProductName ORDER BY Sales DESC
- Close and save the view as TopTen.
NOTE: When you save the TopTen view, you receive the following error message:However, the view returns the results in the correct order. Click OK to close the dialog box.Order by clause may not be used in this query type.
Caption Section: Yes
Record Navigation Section: No
Data Page Size: 10
NOTE: Set the DataPageSize property to the number of records that you expect to get, based on the value that you specify in step 2 of the "Creating the Query or the View" section.
Text Box
-----------
Id: txtRank
Text Box
--------------------------
Id: ProductName
ControlSource: ProductName
Text Box
---------------------------
Id: CategoryName
ControlSource: CategoryName
Text Box
--------------------
Id: Sales
ControlSource: Sales
"... <TEXTAREA id=txtRank style="HEIGHT: 0.166in; ..."
to
"... <TEXTAREA id=txtRank name=txtRank style="HEIGHT: 0.166in; ..."
<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 won't work without it.
<SCRIPT LANGUAGE=vbscript FOR=MSODSC EVENT=Current(oEventInfo)>
<!--
dim cnt
cnt = 1
for each RnkBox in document.all.item("txtRank")
RnkBox.value = cnt
cnt = cnt + 1
next
-->
</SCRIPT>
Additional query words:
Keywords : kbdta AccDAP DAPScriptHowTo dtavbscript
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: July 19, 1999