Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Access Query problem 1

Status
Not open for further replies.

Bill4tektips

Technical User
Aug 5, 2005
175
GB
I have created a query in Access 2003 to count the number of times an article appears in a field. My problem is that I would like to show "0" if nothing is found and not a blank query. Any help would be appreciated.
 
If an empty entry appears, you can use NZ function with the second argument set to 0.

combo
 

Are you also ingnorant of the HELP feature in Access? You might want to give that a try.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Looking up Nz() won't be of much help regarding this thread. Clearly Bill4tektips would like to display a blank record with a 0 in the count which is not possible in a basic select query without some fancy joins.

Assuming a table of colors:
[tt]
tblColors
[color]
Blue
Green
Orange
Red
White
[/tt]
and a table of our favorite colors:
[tt]
tblOurFavs
[TTer] [FavColor]
Skip Red
DHookom Green
Combo White
Bill Green
[/tt]
I expect Bill4tektips wants to query tblOurFavs for "Blue" and display a count field with a 0. This query will not return any rows:
SQL:
SELECT Count(tblOurFavs.TTer) AS CountOfTTer, tblOurFavs.FavColor
FROM tblOurFavs
GROUP BY tblOurFavs.FavColor
HAVING tblOurFavs.FavColor="Orange";
This query will return the results I expect are desired using a LEFT JOIN:
SQL:
SELECT Count(tblOurFavs.TTer) AS CountOfTTer, tblColors.Color
FROM tblColors LEFT JOIN tblOurFavs ON tblColors.Color = tblOurFavs.FavColor
GROUP BY tblColors.Color
HAVING tblColors.Color="Orange";
[tt]
CountOfTTer Color
----------- ------
0 Orange
[/tt]




Duane
Hook'D on Access
MS Access MVP
 
It works OK on "Open" but when I add criteria to see if there are any "Closed" I am just getting a blank query again. My sql is:

This works OK:

SELECT Count(tblfeedback.UKProcessNo) AS CountOfUKProcessNo, tblCycle.CycleName
FROM tblCycle LEFT JOIN tblfeedback ON tblCycle.CycleName = tblfeedback.UKProcessNo
GROUP BY tblCycle.CycleName, tblfeedback.DateofCompletion
HAVING (((tblCycle.CycleName)="CMC 1 Manage Company Strategy") AND ((tblfeedback.DateofCompletion) Is Null));

This doesn't

SELECT Count(tblfeedback.UKProcessNo) AS CountOfUKProcessNo, tblCycle.CycleName, tblfeedback.DateofCompletion
FROM tblCycle LEFT JOIN tblfeedback ON tblCycle.CycleName = tblfeedback.UKProcessNo
GROUP BY tblCycle.CycleName, tblfeedback.DateofCompletion
HAVING (((tblCycle.CycleName)="CLC 1 Win Contract") AND ((tblfeedback.DateofCompletion) Is Not Null));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top