Discussion Locked

Multiple Queries to 1 Report

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
In Access 2k, can you link multiple queries to one report? If so, how?

9 replies

by dklippert

Use the Report Wizard (Reports>New). Choose the queries and field you need and they'll combine on the report

by borginva

When I do that, I get an error.
I have 2 queries, for example, they are set up to give me the total number of certain sites. The results I get is the count of total sites. Just one figure.
So I build a report using the count field of two queries, and the error I get is:

I have choosen fields from record sources which the wizard can't connect. You may have choosen fields from a table and from a query based on that table. If so, try choosing fields from one table or one query.

The problemis that I do not know how to get one query to give me each seperate's one individual results (say 15 and 34). If you can help with that to make this easier, please let me know.

by jim94539

You probably need a union query. Create a new query but don't select any tables for the query. Then go to the toolbar and select Query / SQL Specific / Union. This opens a window that is waiting for SQL instructions. To combine three separate queries into a single result, the following commands would be needed for a query on a table named "Sites" that contains a field labeled "Name". Name can contain a variety of items that include three base names: Dell, Gateway and Microsoft. Here are the SQL instructions for the union query:

SELECT "Dell" AS Site, Count(Sites.Name) AS [Count]
FROM Sites
WHERE (((Sites.Name) Like "*Dell*"))

UNION ALL SELECT "Gateway" AS Site, Count(Sites.Name) AS [Count]
FROM Sites
WHERE (((Sites.Name) Like "*Gateway*"))

UNION ALL SELECT "Microsoft" AS Site, Count(Sites.Name) AS [Count]
FROM Sites
WHERE (((Sites.Name) Like "*Microsoft*"));

Please notice that the 2nd, 3rd, etc. Select commands start with UNION ALL to connect the statements together. Also, only the last statement ends with a semi-colon. This arrangement can be any length desired as long as each Select statement returns the same number of fields (in this case, two visible and one not visible) and all fields names are identical (in this case, Site and Count for the visible fields and Name for the hidden field created by the Where statement).

- Jim

by borginva

That gives me a query that I can use for figures, but I still have several queries that need to be linked for this one report, and I can not pick fields from more than one query. I need to be able to pick fields from multiple queries for one report.That is what I need to do. Is that possible?

by borginva

Now, not only can I not use multiple queries for one report, but that union query, which by itself works, will not be used on a report. I tried adding in just one field of that union query, and I get a bunch of SQL errors.

by jim94539

Yes, the union query will work with any arrangement of select queries as long as the first is written in a normal fashion (with no semicolon at the end) and each added query starts with Union All. Only the last query statement ends with a semicolon.

Write each query separately using the Access tools. Copy the SQL statements of each into a new Union query and edit it to eliminate the semicolons and add the Union All statements.

The Union query must be created as an SQL query because Access doesn't provide the query builder interface for this special query.

- Jim

This discussion is closed to new replies.