Infinite opportunities?  Endless problems?  Limited resources?  Talk to us!
Operations
Consulting
Software
Consulting
Publishing and
Training
Applied
Solutions
Excel add-ins
and tutorials
Charts Excel and VBA
Case Studies
VBA
tutorials
PowerPoint
Add-Ins
Miscellenia
You are on the Home/Excel/Tutorials/RDBMS in Excel/Build Queries/Query 4 page

Building and using a relational database in Excel (with a little help from MS Query)

Building the queries

Query 4 -- A parameterized query to list of customers in a zip code that is specified dynamically

Now that we know how to link to MS Query, how to add tables to a query within MS Query, how to add fields to the query, and how to return data to Excel, we can expedite building this query.  Once in MS Query add the Customers table to the query.  Then, use View | Criteria to see the Criteria pane.  This works very similar to where we select the fields to display.  In the Value row, one can either enter a specific value or defer the decision to the time when the query is executed.  To do the latter, enclose the text in square brackets as shown below, making sure to not use the name of an actual field.

 

About this site

What's new

Google
Web
This Site
 

 

Select File | Return data to Microsoft Office Excel to return to Excel.  MS Query will try and run the query and since it needs to know what zip code to use, it will pop up with a dialog box like:

Enter any value and click OK.

Back in Excel, note that the dialog box does not offer a choice to Create a PivotTable report...  This is because PivotTables do not support parameterized data sources.

Also, note the Parameters... button.  This makes it possible to tell Excel where to find the value it needs to run the query.  Click the button to get

This is where we get to see the real power of a parameterized MS Query.  Select the last option Get the value from the following cell.  This enables the field to specify the cell and the checkbox Refresh automatically when cell value changes.  As the name implies, the query will be rerun whenever the parameter value in the specified cell changes.

Select some cell, say B4, and select the checkbox.

The result

Now, enter another zip code, say 14627 and the result will change to

Next: Query 5: Select the zip code from a drop down box -- build a cascading query

 

 

For custom technology solutions, operations consulting, or training contact web-underscore-contact@tushar-hyphen-mehta-dot-cee-oh-em.
By accessing any page or link on this web site other than this page, you agree to the terms and conditions.

Ads from amazon.com

[Optional] Survey (current rating of site: 3.7 out of 4)  If you will take a moment to provide your comments, it will help improve the site both for you, and for other visitors.

On a scale of 4 (just what I need)
to zero (totally useless)

How do you rate the information

on this page?

  on this site?

[Optional]

Your name
Your email address
Other comments
 
Monitor page
for changes
    
   it's private  

by ChangeDetection
A comment selected at random:

 

 

Copyright © 2000-2008 Tushar Mehta.
Send comments and suggestions about the web site to webmaster@tushar-hyphen-mehta-dot-cee-oh-em
Last edited April 13, 2008