combobox rowsource "All" if more than one in list

D

deb

access 2003

I have a combobox with the below row source. It contains a Union to add
"All units".

How can I edit this to only show "All Units" if there are more than one
selection in the combobox?

i.e.
if combobox rowsource has 3 units then "All Units" would be included.
if combobox rowsource has only 1 unitthen only list the one unit.

SELECT t000GFacts.UnitID, t000GFacts.Unit, t000GFacts.UnitType,
t000GFacts.AEIC, t000GFacts.PlantName, t000GFacts.Unit AS UnitOrder,
t000GFacts.SiteName, t000GFacts.OperatingCompany AS Customer,
t000GFacts.ProjectNo, t000GFacts.SiteID, t000GFacts.PlantID,
t040Project.ProjectID FROM t040Project INNER JOIN (t000GFacts INNER JOIN
t041ProjectDetails ON t000GFacts.UnitID = t041ProjectDetails.UnitID) ON
t040Project.ProjectID = t041ProjectDetails.ProjectID WHERE
(((t040Project.ProjectID) Like [Forms]![f001ProjectReview]![ProjectID]))

UNION SELECT 0 AS UnitID, "All Units" AS Unit, "" AS UnitType, "" AS AEIC,
"" AS PlantName, "" AS UnitOrder, "" AS SiteName, "" AS Customer, "" AS
ProjectNo, "" AS SiteID, "" AS PlantID, t040Project.ProjectID FROM
t040Project INNER JOIN (t000GFacts INNER JOIN t041ProjectDetails ON
t000GFacts.UnitID = t041ProjectDetails.UnitID) ON t040Project.ProjectID =
t041ProjectDetails.ProjectID WHERE (((t040Project.ProjectID) Like
[Forms]![f001ProjectReview]![ProjectID]))
ORDER BY t000GFacts.PlantName, t000GFacts.Unit;



Thanks bunches,
 
D

Dirk Goldgar

deb said:
access 2003

I have a combobox with the below row source. It contains a Union to add
"All units".

How can I edit this to only show "All Units" if there are more than one
selection in the combobox?

i.e.
if combobox rowsource has 3 units then "All Units" would be included.
if combobox rowsource has only 1 unitthen only list the one unit.

SELECT t000GFacts.UnitID, t000GFacts.Unit, t000GFacts.UnitType,
t000GFacts.AEIC, t000GFacts.PlantName, t000GFacts.Unit AS UnitOrder,
t000GFacts.SiteName, t000GFacts.OperatingCompany AS Customer,
t000GFacts.ProjectNo, t000GFacts.SiteID, t000GFacts.PlantID,
t040Project.ProjectID FROM t040Project INNER JOIN (t000GFacts INNER JOIN
t041ProjectDetails ON t000GFacts.UnitID = t041ProjectDetails.UnitID) ON
t040Project.ProjectID = t041ProjectDetails.ProjectID WHERE
(((t040Project.ProjectID) Like [Forms]![f001ProjectReview]![ProjectID]))

UNION SELECT 0 AS UnitID, "All Units" AS Unit, "" AS UnitType, "" AS AEIC,
"" AS PlantName, "" AS UnitOrder, "" AS SiteName, "" AS Customer, "" AS
ProjectNo, "" AS SiteID, "" AS PlantID, t040Project.ProjectID FROM
t040Project INNER JOIN (t000GFacts INNER JOIN t041ProjectDetails ON
t000GFacts.UnitID = t041ProjectDetails.UnitID) ON t040Project.ProjectID =
t041ProjectDetails.ProjectID WHERE (((t040Project.ProjectID) Like
[Forms]![f001ProjectReview]![ProjectID]))
ORDER BY t000GFacts.PlantName, t000GFacts.Unit;


I'm not sure I'm going to get this right without setting up tables to test
with, but try this:

SELECT t000GFacts.UnitID, t000GFacts.Unit, t000GFacts.UnitType,
t000GFacts.AEIC, t000GFacts.PlantName, t000GFacts.Unit AS UnitOrder,
t000GFacts.SiteName, t000GFacts.OperatingCompany AS Customer,
t000GFacts.ProjectNo, t000GFacts.SiteID, t000GFacts.PlantID,
t040Project.ProjectID FROM t040Project INNER JOIN (t000GFacts INNER JOIN
t041ProjectDetails ON t000GFacts.UnitID = t041ProjectDetails.UnitID) ON
t040Project.ProjectID = t041ProjectDetails.ProjectID WHERE
(((t040Project.ProjectID) Like [Forms]![f001ProjectReview]![ProjectID]))
UNION ALL
SELECT 0 AS UnitID, "All Units" AS Unit, "" AS UnitType, "" AS AEIC,
"" AS PlantName, "" AS UnitOrder, "" AS SiteName, "" AS Customer, "" AS
ProjectNo, "" AS SiteID, "" AS PlantID, t040Project.ProjectID FROM
t040Project INNER JOIN (t000GFacts INNER JOIN t041ProjectDetails ON
t000GFacts.UnitID = t041ProjectDetails.UnitID) ON t040Project.ProjectID =
t041ProjectDetails.ProjectID WHERE (((t040Project.ProjectID) Like
[Forms]![f001ProjectReview]![ProjectID]))
GROUP BY 0, t040Project.ProjectID
HAVING Count(*) > 0
ORDER BY t000GFacts.PlantName, t000GFacts.Unit;
 
D

Dirk Goldgar

Dirk Goldgar said:
I'm not sure I'm going to get this right without setting up tables to test
with, but try this:

SELECT t000GFacts.UnitID, t000GFacts.Unit, t000GFacts.UnitType,
t000GFacts.AEIC, t000GFacts.PlantName, t000GFacts.Unit AS UnitOrder,
t000GFacts.SiteName, t000GFacts.OperatingCompany AS Customer,
t000GFacts.ProjectNo, t000GFacts.SiteID, t000GFacts.PlantID,
t040Project.ProjectID FROM t040Project INNER JOIN (t000GFacts INNER JOIN
t041ProjectDetails ON t000GFacts.UnitID = t041ProjectDetails.UnitID) ON
t040Project.ProjectID = t041ProjectDetails.ProjectID WHERE
(((t040Project.ProjectID) Like [Forms]![f001ProjectReview]![ProjectID]))
UNION ALL
SELECT 0 AS UnitID, "All Units" AS Unit, "" AS UnitType, "" AS AEIC,
"" AS PlantName, "" AS UnitOrder, "" AS SiteName, "" AS Customer, "" AS
ProjectNo, "" AS SiteID, "" AS PlantID, t040Project.ProjectID FROM
t040Project INNER JOIN (t000GFacts INNER JOIN t041ProjectDetails ON
t000GFacts.UnitID = t041ProjectDetails.UnitID) ON t040Project.ProjectID =
t041ProjectDetails.ProjectID WHERE (((t040Project.ProjectID) Like
[Forms]![f001ProjectReview]![ProjectID]))
GROUP BY 0, t040Project.ProjectID
HAVING Count(*) > 0
ORDER BY t000GFacts.PlantName, t000GFacts.Unit;


Correction:

HAVING Count(*) > 1
 
D

deb

works like a dream!!!
--
deb


Dirk Goldgar said:
Dirk Goldgar said:
I'm not sure I'm going to get this right without setting up tables to test
with, but try this:

SELECT t000GFacts.UnitID, t000GFacts.Unit, t000GFacts.UnitType,
t000GFacts.AEIC, t000GFacts.PlantName, t000GFacts.Unit AS UnitOrder,
t000GFacts.SiteName, t000GFacts.OperatingCompany AS Customer,
t000GFacts.ProjectNo, t000GFacts.SiteID, t000GFacts.PlantID,
t040Project.ProjectID FROM t040Project INNER JOIN (t000GFacts INNER JOIN
t041ProjectDetails ON t000GFacts.UnitID = t041ProjectDetails.UnitID) ON
t040Project.ProjectID = t041ProjectDetails.ProjectID WHERE
(((t040Project.ProjectID) Like [Forms]![f001ProjectReview]![ProjectID]))
UNION ALL
SELECT 0 AS UnitID, "All Units" AS Unit, "" AS UnitType, "" AS AEIC,
"" AS PlantName, "" AS UnitOrder, "" AS SiteName, "" AS Customer, "" AS
ProjectNo, "" AS SiteID, "" AS PlantID, t040Project.ProjectID FROM
t040Project INNER JOIN (t000GFacts INNER JOIN t041ProjectDetails ON
t000GFacts.UnitID = t041ProjectDetails.UnitID) ON t040Project.ProjectID =
t041ProjectDetails.ProjectID WHERE (((t040Project.ProjectID) Like
[Forms]![f001ProjectReview]![ProjectID]))
GROUP BY 0, t040Project.ProjectID
HAVING Count(*) > 0
ORDER BY t000GFacts.PlantName, t000GFacts.Unit;


Correction:

HAVING Count(*) > 1

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

report record source 6

Top