XL98: How to Create Parameter Queries

Last reviewed: February 2, 1998
Article ID: Q180184
The information in this article applies to:
  • Microsoft Excel 98 Macintosh Edition

SUMMARY

A parameter query is a kind of query that prompts you to specify values that are used to select the records for the result set. This allows the same query to be used to retrieve different results. You can create a custom prompt that describes the requested parameter and that is displayed when the query is run.

MORE INFORMATION

A result set is a set of records that results when you run a query. You can see the result set of a query in Microsoft Query or you can return a result set to a Microsoft Excel worksheet for further analysis. Microsoft Query displays the result set in row-and-column format in the Data pane.

The criteria is one or more conditions you specify to limit which records are included in the result set of a query.

Example

The following example, using the sample dBASE file Order.dbf, creates a parameter query that selects records by city. When you run the query, a prompt appears and displays "Type the name of the city." The result set returns only the records for the city that is entered by the user.

NOTE: a parameter query is case-sensitive.

To use this example, follow these steps:

  1. On the Apple Menu, point to Control Panels and click ODBC Setup PPC. In the User DSN tab, click Add.

  2. In the Create New Data Source dialog box, click Microsoft 3.01 dBASE PPC and click Finish.

  3. In the General tab, type "TestDBF" (without the quotation marks) for the Data Source Name. Click Select Directory and select the Sample Databases folder located under the Microsoft Office 98:Sample Files folder.

  4. In the ODBC Data Source Administrator, click OK.

  5. Start Microsoft Excel. Point to Get External Data on the Data menu and click Create New Query.

  6. In the Choose Data Source dialog box, click TestDBF*. Clear the Use The Query Wizard check box. Click OK.

  7. In the Add tables dialog box, click Customer.dbf. Click Open and click Cancel.

    The Customer table should be added to Microsoft Query.

  8. In Microsoft Query, double-click the asterisk in Customer table to add all the records to the Data Pane.

  9. On the View menu, click Criteria. Click City in the Criteria Field. In the Value field type the following:

    ["Enter a city."]

  10. If the Enter Parameter Value dialog box appears, type "Seattle" (without the quotation marks). On the File menu, click "Return Data to Microsoft Excel."

  11. In the "Returning External Data to Microsoft Excel" dialog box, click Existing worksheet and =$a$1. Click OK.

  12. In the Enter Parameter Value dialog box, type "Seattle" (without the quotation marks).

    NOTE: This dialog box is case sensitive.

To change parameter value after data is returned to the worksheet, click Refresh Data on the Data menu.

Using the Like Operator

To return all the data in a parameter query or partially matching records in a field, ensure that when you create the parameter, the leading parameter bracket ([) is preceded by the operator LIKE. LIKE is used in conjunction with the % wildcard. The % wildcard is similar to the * wildcard in MS-DOS, which returns all characters.

For example, using the example above, change the parameter in step 9 from the following

   ["Enter a city."]

to the following

   Like ["Enter a city."]

To use this parameter and return all records that begin with the letter "S," type "S%" (without the quotation marks) in the Enter Parameter Value dialog box. To return all records, enter the % by itself.

For additional information, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q164117
   TITLE     : XL97: How to Use Wildcards in Parameter Queries

   ARTICLE-ID: Q179700
   TITLE     : XL98: "Out of Range" Error Running Parameter Query in
               MS Query


Additional query words: OFF98 xl98 msquery
Keywords : xlquery
Version : MACINTOSH:98
Platform : MACINTOSH
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 2, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.