You probably don't need to have 13 separate queries. If you count fields,
all fields that are null will not get counted. Any field with a value will
be counted. So you could use something like the query below to count fields
that have a value by field.
John Vinson's method of Count(*) is a special case, it counts the rows
returned by the query. It is also supposed to be faster then counting
values in a field.
Example (replace generic field names with your field names)
SELECT TMain.Area, TMain.Status,
Count(TMain.ISPS) as CountISPS,
Count([Another Field]) as CountAnother,
Count([Field xx]) as CountFieldXX
FROM TMain
WHERE TMain.Area is Not Null AND TMain.Status="Active"
GROUP BY Area, Status
ORDER BY TMain.Area;
That could return something like the following (colons represent column
breaks)
Area51 : Active : 12 : 10 : 23
DWX : Active : 92 : 12 : 17
Dear John Spencer
Your suggestion worked even better. It is producing the EXACT result I am
looking for, BUT (again) it won't allow me to produce result for more than 3
fields. I get and error like so:
"The SELECT statement includes a reserved word or an argument that is
misspelled or missing, or the punctuation is incorrect."
and it highlights the 'Count' word for my 4th field. here is my SQL so far:
SELECT TMain.Area, TMain.Status,
Count(TMain.ISPS) as ISPS,
Count(TMain.SST) as SST,
Count(TMain.[Level 1 Anti-Terrorism]) as Level1
Count(TMain.[Non-Lethal Tactics]) as NonL
FROM TMain
WHERE TMain.Area is Not Null AND TMain.Status="Active"
GROUP BY Area, Status
ORDER BY TMain.Area;
'Count' for NonL gets highlighted and wont work, but without the 4th field,
it works fine. Is there a limit to how many fields I can use in this kind of
statement? I have 12 I need to produce answers for altogether.
Thank you for all your help.
Rigby
> You probably don't need to have 13 separate queries. If you count fields,
> all fields that are null will not get counted. Any field with a value will
[quoted text clipped - 87 lines]
> >>
> >> John W. Vinson[MVP]
John Spencer - 29 Mar 2006 13:50 GMT
You are missing a comma after "as Level1" in your post. I assume that is
the problem and is not a typo in your posting.
A little trick you can use is to format the query slightly different. The
problem is that Access won't keep this formatting, but it does help in
construction sometimes. That is to put the comma before the field and on a
new line. See my example below. I find it easy to scan down and see that
all the required commas are there.
SELECT TMain.Area
, TMain.Status
, Count(TMain.ISPS) as ISPS
, Count(TMain.SST) as SST
, Count(TMain.[Level 1 Anti-Terrorism]) as Level1
, Count(TMain.[Non-Lethal Tactics]) as NonL
FROM TMain
WHERE TMain.Area is Not Null AND TMain.Status="Active"
GROUP BY Area, Status
ORDER BY TMain.Area;
Access (bless its little heart) rearranges this into:
SELECT TMain.Area, TMain.Status, Count(TMain.ISPS) as ISPS, Count(TMain.SST)
as SST, Count(TMain.[Level 1 Anti-Terrorism]) as Level1,
Count(TMain.[Non-Lethal Tactics]) as NonL
FROM ...
which is a lot harder to check.
> Dear John Spencer
>
[quoted text clipped - 130 lines]
>> >>
>> >> John W. Vinson[MVP]
rigby - 29 Mar 2006 14:22 GMT
John Spencer
You are a champion. It has done exactly as I needed. Thank you so much for
all of your help.
Kind regards
Rigby
> You are missing a comma after "as Level1" in your post. I assume that is
> the problem and is not a typo in your posting.
[quoted text clipped - 157 lines]
> >> >>
> >> >> John W. Vinson[MVP]
John Spencer - 29 Mar 2006 15:14 GMT
Great, I'm glad that worked for you.
> John Spencer
>
[quoted text clipped - 182 lines]
>> >> >>
>> >> >> John W. Vinson[MVP]