ACC: Adding a Parameter to a Union QueryID: Q132135
|
Moderate: Requires basic macro, coding, and interoperability skills.
An easy way to prompt a user for a search criteria in a query is to create
a parameter query. However, to use a parameter in a union query, you must
follow some specific rules. This article uses the Customers and Suppliers
By City query in the sample database Northwind.mdb to describe how to add a
parameter to a union query.
NOTE: In Microsoft Access 2.0, a similar query called Union Query can be
found in the sample database NWIND.MDB.
The Customers and Suppliers By City union query selects records from both
the Customers and Suppliers tables. The SQL of this query is as follows:
SELECT City, CompanyName, ContactName, "Customers" AS [Relationship]
FROM Customers
UNION SELECT City, CompanyName, ContactName, "Suppliers"
FROM Suppliers
ORDER BY City, CompanyName;
SELECT [Company Name], [City]
FROM [Suppliers]
WHERE Country = "Brazil"
UNION SELECT [Company Name], [City]
FROM [Customers]
WHERE Country = "Brazil";
SELECT City, CompanyName, ContactName, "Customers" AS [Relationship]
FROM Customers
WHERE Country = "Brazil" and City = [Enter City]
UNION SELECT City, CompanyName, ContactName, "Suppliers"
FROM Suppliers
WHERE Country = "Brazil" and City = [Enter City]
ORDER BY City, CompanyName;
SELECT [Company Name], [City]
FROM [Suppliers]
WHERE Country = "Brazil" and City = [Enter City]
UNION SELECT [Company Name], [City]
FROM [Customers]
WHERE Country = "Brazil" and City = [Enter City];
For more information about union queries, search for "union queries," and then "Combine data in fields from two or more tables using a union query" using the Microsoft Access 97 Help Index.
Keywords : kbusage QryUnion
Version : 2.0 7.0 97
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 23, 1999