Count # of records in a report, using a filter.

brunces

Registered User.
Local time
Today, 02:15
Joined
Sep 12, 2004
Messages
45
Hi, friends.

I'm trying to count records in a report, using a filter but I'm not doing well with it...

In my report there are these fields:

- Car_Plate
- Car_Model
- Car_Color
Etc.

The report shows all the cars. But at the bottom, I want to count specific ones. For example:

Number of cars in color "BLUE":

I've tried these expressions (in a textbox)...

=DCount("*", "Car_Color = 'blue'")
=DCount("*", "ReportName", "Car_Color = 'blue'")

I know, there's something wrong, but I don't know what! And I'm sure it must be ridiculously simple! :D

In other post, I asked about counting records from a query, in a textbox in a report. A good friend, "theprez", answered me with this:

=DCount("*", "QueryName")

I just added the filter:

=DCount("*", "QueryName", "Car_Color = 'blue'")

And it worked very well! Exactly the way I needed.

But, what if I want to do the same count from the report itself? Or any other report as well?

Thank you all for the attention.

Hugz.

Bruno
 
Last edited:
In the DCOUNT command, you do not necessarily have to use a query, you can use a table name. Here is the syntax:

DCount(expr, domain[, criteria])

The domain can be a query or table. Use whatever recordset the report is based upon. If the report is based on a table use:

=DCount("*", "TableName", "Car_Color = 'blue'")

Also, just a thought here: If you want to list all the colors for the cars and their counts, without worrying about knowing what colors to put in your criteria, write a summation query that groups by Car_Color. Written Correctly, it will appear like this

Red 80
Blue 45
Black 2
 
Last edited:
theprez,

Thank you for your attention. I understood the point. It worked out. :)

Hugz.

Bruno
 
DCount is slow and in this case you don't need it since the values are already on your Report.
=Sum(Iif([Car_Color]="Blue")1,0) as the control source of an unbound textbox on your report will work faster
 

Users who are viewing this thread

Back
Top Bottom