You need square brackets around any field or table name (or alias for them)
that contains spaces, is a reserved word, or contains any characters besides
letters, numbers, and the underscore character.
Also the semi-colon indicates END OF QUERY so you need to remove that from the
first query in the UNION query. Those changes should leave you with a query
that looks like the following:
SELECT "Unscheduled_Production" as OriginalTable
, Work_Center as [Work Center]
, Work_Center_Description as [Work Center Description]
, Material as IDH
, Material_Description as [IDH Description]
, Delivered_Quantity as Produced
FROM Unscheduled_Production
UNION ALL
SELECT "Excess_Production"
, Work_Center
, Work_Center_Description
, Material
, Material_Description
, Excess_Production
FROM Excess_Production;
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
GoBrowns! said:
Duane;
I am having this exact problem and tried to write the Union query in SQL,
but I keep getting the error that the select statement includes a reserved
work or an argument name that is misspelled or missing. Here are the two
queries I am trying to unite:
Unscheduled_Production
================
Work_Center
Work_Center_Description
Material
Material_Description
Delivered_Quantity
....
Excess_Production
============
Work_Center
Work_Center_Description
Material
Material_Description
Excess_Production
Here is what I put in SQL:
SELECT "Unscheduled_Production" as OriginalTable, Work_Center as Work
Center, Work_Center_Description as Work Center Description, Material as IDH,
Material_Description as IDH Description, Delivered_Quantity as Produced;
FROM Unscheduled_Production
UNION ALL
SELECT "Excess_Production", Work_Center, Work_Center_Description, Material,
Material_Description, Excess_Production
FROM Excess_Production;
Can you please help me troubleshoot?
Thanks!
:
Assuming you have two similar tables (our queries) like:
tblCustomers
================
CustomerID
ContactFName
ContactLName
ContactTitle
.....
tblSuppliers
==================
SupplierID
SupplierFirstName
SupplierLastName
SupplierTitle
.....
You can create a single list of all customer contacts and suppliers with a
union query like:
SELECT "Customers" as OriginalTable, CustomerID as ID, ContactFName as
FName, ContactLName as LName, ContactTitle as Title
FROM tblCustomers
UNION ALL
SELECT "Suppliers", SupplierID, SupplierFirstName, SupplierLastName,
SupplierTitle
FROM tblSuppliers;
This can be created only in the SQL view of your query design.
--
Duane Hookom
MS Access MVP
I've not yet heard of a Union query. Would you explain?
Thanks.
:
If the subreport method doesn't work, you might be able to create a union
query to use as the Record Source of the main report and then not use the
subreport.
--
Duane Hookom
MS Access MVP
Thanks Duane, simple enough.
My main report is a simple listing of select records from a table (with
column headers). The sub report is something similar. How can I get the
report to start listing the second list right after the first list is
finished. The number of records in both reports can vary.
dbs
:
Place the final subreport in the Report Footer section so it only
prints
once on the main report.
--
Duane Hookom
MS Access MVP
I have two parameter queries that create the output I'm looking for.
Both
queries use the same input. I now want to combine these two queries
in
one
report such that the complete results from the first query is
printed
first
and the complete results of the second are printed next. Both
queries
report
columns from tables. I don't need to total anything. It would be
nice
to
report the input parameter on the top of the page as well but that
would
be
icing on the cake.
I tried creating a main report and then adding a subreport (to the
detail
section) but my output is a mess. I get the first line from the
first
query
followed by the entire second query and then it repeats only with
the
second
line from the first query and so on. While I figured adding the
subreport
to
the detail section would produce the results I got, I don't know
what
to
try
next.
Any help you could provide would be appreciated.