473,395 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to apply filter to count in report

AccessIdiot
493 256MB
This seems like it should be really easy and I think I'm just missing something really dumb.

I have a form that filters a report. At the top of the report I have a bunch of unbound text boxes that do simple things like count and sum. When I apply the filter to the report the text boxes update beautifully when their control source is something like
Expand|Select|Wrap|Line Numbers
  1. =sum([num hatched])
However now I want to apply a clause. If I do this:
Expand|Select|Wrap|Line Numbers
  1. =dcount("[num hatched]", "[tbl_nesting]","[num hatched]>0")
then I get a number but it's ALWAYS that number despite the filter. I want it just to count what's displayed after the filter but
Expand|Select|Wrap|Line Numbers
  1. =dcount([num hatched]>0) 
doesn't work, just reports a false count.

What am I doing wrong?
Jul 13 '10 #1

✓ answered by AccessIdiot

Got it. I needed an IIF statement.

Expand|Select|Wrap|Line Numbers
  1. =Count(IIf([Num Hatched]>0,0))

7 5484
NeoPa
32,556 Expert Mod 16PB
There's quite a difference between the Aggregate functions and the Domain Aggregate functions.

In a report a Domain Aggregate function (DCount()) is self-contained. You must specify the record source etc. With an Aggregate function (Sum()) it refers to controls accessible (generally in the Detail section) in your report. Not fields notice (which are references to the underlying data source), but the controls.
Jul 13 '10 #2
NeoPa
32,556 Expert Mod 16PB
You also mention filtering the report. As far as I'm aware, filtering is always applied to the recordsource, and is never effected by the values in controls. Does this help to understand?
Jul 13 '10 #3
AccessIdiot
493 256MB
Kind of. I had figured out that Count was going to work better than DCount, but I can't figure out how to phrase the statement I want with the rule applied (e.g. count, which works, vs. count where field value > 0, which doesn't work). Can you apply a rule like that in an aggregate function? I am useless with the expression builder - it is not very intuitive to me.
Jul 14 '10 #4
AccessIdiot
493 256MB
Got it. I needed an IIF statement.

Expand|Select|Wrap|Line Numbers
  1. =Count(IIf([Num Hatched]>0,0))
Jul 14 '10 #5
NeoPa
32,556 Expert Mod 16PB
AccessIdiot:
Expand|Select|Wrap|Line Numbers
  1. =Count(IIf([Num Hatched]>0,0))
You did, but I suggest one more like :
Expand|Select|Wrap|Line Numbers
  1. =Count(IIf([Num Hatched]>0,1,0))
Jul 14 '10 #6
AccessIdiot
493 256MB
Can you translate that into a full sentence for me? I didn't fully understand even in the one that worked for me why 0 was used for "true" and not 1. In my binary world we always use 0 for false an 1 for true.

So my own example would read:
"If num hatched > 0, then false" which obviously isn't the case. And I'd read your statement to read:
"If num hatched > 0, then true, else false."

So why do the 0's and 1's get switched around? Of is mine just shorthand where the first/only comma is the else statement? Did I just answer my own question lol?
Jul 14 '10 #7
AccessIdiot
493 256MB
Actually A your statement didn't work? Now I'm doubly confused.
Jul 14 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Iyhamid | last post by:
Hi I am looking for codes to filter and apply filter to my data base using access
3
by: mattscho | last post by:
Hi All, Trying to create a set of 3 buttons in a form that have the same effect as the "Filter by Form", "Apply Filter" and "Remove Filter" Buttons on the access toolbar. Help would be muchly...
1
by: mattscho | last post by:
Re: Filter By From, Apply Filter, Remove Filter Buttons in a Form. -------------------------------------------------------------------------------- Hi All, Trying to create a set of 3 buttons in...
4
by: Fran | last post by:
I recently tried to use code for "Use a multi-select list box to filter a report" from Allen Browne in my database. I was able to add the code and adapt it to my needs, however I am getting an...
3
by: Supermansteel | last post by:
I am trying to run a Apply filter for everytime someone opens Form_CC it will only show the Test (Test_ID) they are working on. This seems to be the closest I have gotten to filtering it correctly,...
3
by: Gord | last post by:
I'm trying to filter a report with a date in VB code. If I type an actual date bracketed with the pound symbol (i.e. #3-Jul-08#) I can get the filter to work. I can't seem to get it to work by...
1
by: eHaak | last post by:
A couple years ago, I built a database in MS Access 2003. I built the form using macros in some of the command buttons, and now I’m trying to eliminate the macros and just use visual basic code. ...
3
by: dbdb | last post by:
hi guys need your suggestion how can i apply filter for my date variable data type i have a form name transaction and i have a text box on it named : start and finish i need to apply...
10
by: dbdb | last post by:
Hi, i create a chart in ms access based on my query, then i want my chart when is it open is only show value based on my criteria. i'll try to used it in the properties apply filter using the...
1
by: Azriel928 | last post by:
I know this is a simple function to program, but I'm a little rusty. I'm trying to set the "On Open" event on a report using a macro to apply a filter that I have saved as a query. Can you please...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.