View Full Version : DCount


coastiegirl
04-24-2002, 04:39 AM
Hello,
I am trying to use DCount as the field expression in my query. What I want it to do is count how many records in the table equal a certain criteria. I will then output all of this into a report. My problem is that I can get it to count the records in the table but it gives me back the same amount of records that are in the table. This means that when I go to a report and print it will list this answer to the criteria for as many records that are in the table.

EX: I want the query to count how many records that have "hazmat" in the cargo field. I have 5 records in the table. The output is "5" for the expression listed 5 times to correspond with how many records are in the table. When printed in a report it is supposed to look like this:
How many cont. are hazmat: 5
what it is returning is
How many cont. are hazmat: 5
How many cont. are hazmat: 5
How many cont. are hazmat: 5
How many cont. are hazmat: 5
How many cont. are hazmat: 5

I only want it the one time. Does anyone know how to get the query to only give me one record with the count.

RV
04-24-2002, 09:30 AM
Don't use DCount but Count.
The outcome of DCount is stated as result for each record found in your table meeting the WHERE clause in your DCount function.

The Sql statement becomes like this:

SELECT Count(*)
FROM YourTable
WHERE CargoField = "hazmat";

Greetings,

RV