The following example uses the sample database Northwind.mdb. The first drop-down list contains all of the available customers and the second drop-down list contains all of the available orders for the customer selected in the first drop-down list.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements.
- Open the sample database Northwind.mdb.
- In the Database window, click Pages under Objects, and then click New.
- In the New Data Access Page dialog box, click Design View, and then click OK.
- If the toolbox is not already visible, click Toolbox on the View menu.
- Use the Control Wizard to create a new drop-down list that is based on the Customers table. To make sure that you are using the Control Wizard, go to the toolbox and click the Control Wizards button, so that it appears to be pressed in.
- Include the following fields in the control's source:
- Change the ID property of the CustomerID control to ddlCustomer.
- Create a second drop-down list on the page that is based on the Orders table.
- Include the following field in the control's source:
- Change the ID property of the OrderID control to ddlOrder.
- On the Tools menu, point to Macro, and then click Microsoft Script Editor.
- In the Script Outline pane of the Script Editor, browse to the onchange event of the ddlCustomer control.
- Type the following script for the event:
'There are three values in this line of script that will need to be altered
'to port this successfully to another page.
'
'Orders is the table on which the secondary dropdown list is based.
'CustomerID is the name of the field common to both dropdown lists.
'ddlCustomer is the name of the primary dropdown list.
'
MSODSC.RecordsetDefs.Item("Orders").ServerFilter = "[CustomerID]='" & ddlCustomer.value & "'"
- In the Script Outline pane of the Script Editor, browse to the onload event of the window control.
- Type the following script for the event:
- In the Script Outline pane of the Script Editor, browse to the Current event of the MSODSC control.
- Type the following script for the event:
MSODSC.RecordsetDefs.Item("SubAreas").ServerFilter = ""
MSODSC.RecordsetDefs.Item("SubSubAreas").ServerFilter = ""
- Modify the script Current event script tag created in step 17 from
<script language=vbscript for=MSODSC event=Current>
to:
<script language=vbscript for=MSODSC event=Current(obj)>
- Locate the Microsoft Office Data Source Control (MSODSC) in the Script Editor pane. This control is represented by an Access icon by default.
- Place the following code immediately after the MSODSC control, including the script tags.
<SCRIPT>
MSODSC.RecordsetDefs.Item("Orders").ServerFilter = "1=0"
</SCRIPT>
- On the File menu, click Save.
- On the File menu, click Exit.
- On the View menu, click Page View.
Test the behavior of the two drop-down lists. Note that the selection you make in the
ddlCustomer control filters the values available in the
ddlOrders control.