ACC2000: How to Use Server Filters on Data Access Pages Without a Web Server

ID: Q237377


The information in this article applies to:
  • Microsoft Access 2000

Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and a Microsoft Access project (.adp).


SUMMARY

This article demonstrates how to create script that filters a data access page by setting the ServerFilter property. You can use this script even when the page is not stored on a Web server.


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 steps demonstrate how to create a page based on the Customers table. When you open the page or click the New Filter button, the script prompts you for a list of countries. The script then limits the number of records returned based on the countries that you entered. You can return all records by leaving the list empty.

CAUTION: Following the steps in this example will modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and perform these steps on a copy of the database.

  1. Open the sample database Northwind.mdb.


  2. Create a new page in Design view.


  3. If the field list is not visible, on the View menu, click Field List.


  4. From the Customers table, drag the CustomerID, CompanyName, City, Region, and Country onto the page.


  5. Add a command button to the page and set the following properties:


  6. 
       ID: cmdFilter
       Inner Text: New Filter 
  7. On the Tools menu, point to Macro, and then click Microsoft Script Editor.


  8. On the HTML menu, point to Script Block, and then click Client. Type the following script:


  9. 
    <SCRIPT language=vbscript>
    <!--
    Function SetServerFilter()
    
    Dim strFilter, myFilter
    
    strPrmt = "What country do you want to filter by?" & vbCrLf & _
              "Separate the list of countries by a semicolon (;)." _
              & vbCrLf & "To return all records, leave the box empty."
    
    ' Prompt the user for list of countries that are to be returned.
    strFilter = InputBox(strPrmt)
    
    If strFilter = "" Then
       ' Clear the filter criteria when nothing is typed in the input box.
       ' All records are returned in this case.
       myFilter = ""
    Else
       ' Loop through the user's list until there is only one country left. 
       Do Until InStr(strFilter, ";") = 0
          ' Add the first country from the list to the filter criteria.
          myFilter = myFilter & "[Country] = " & Chr(39) & Left(strFilter, _
            InStr(strFilter, ";") - 1) & Chr(39) & " OR "
          ' Remove the first country from the list.
          strFilter = Right(strFilter, Len(strFilter) - InStr(strFilter, _
            ";") - 1)
       Loop
       ' Add the final country from the user's list to the filter criteria.
       myFilter = myFilter & "[Country] = " & Chr(39) & strFilter & Chr(39)
    End If
    
    ' Set the server filter.
    MSODSC.RecordsetDefs.Item(0).ServerFilter = myFilter
    
    End Function
    -->
    </SCRIPT> 
  10. Using the Script Outline, insert the following script for the DataPageComplete event of the MSODSC:


  11. 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 won't work without it.
    
    <SCRIPT LANGUAGE=vbscript FOR=MSODSC EVENT=DataPageComplete(oEventInfo)>
    <!--
    SetServerFilter
    -->
    </SCRIPT> 
  12. Using the Script Outline, insert the following script for the OnClick event of the cmdFilter button:


  13. 
    <SCRIPT LANGUAGE=vbscript FOR=cmdFilter EVENT=onclick>
    <!--
    SetServerFilter
    -->
    </SCRIPT> 
  14. Close the Microsoft Script Editor and save the page as dapSvrFilterEx.


  15. On the View menu, click Page View.


  16. In the dialog box, type Canada; Mexico; USA. Click OK. There should be approximately 21 records.


Additional query words: programmatically

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


Last Reviewed: August 24, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.