473,386 Members | 1,842 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,386 software developers and data experts.

Quick question about Count expression

I tried doing a search for this, but I think the terms I need to use are too generic to come up with anything useful.

Basically, I have a yes/no field in a query that is the record source for a sub form. I am trying to get one text box to show the number of Yes', and another one to show the number of No's.

On the Text Box's control source, I assumed that since you can type "=Count([FieldName])" to get a regular count, you could type "=Count([FieldName]=0)" or "=Count([FieldName]=True)" or something like that to pick out the values you want. Unfortunately, this is not the case; all three expressions just return the total count. Is there any way to do this easily, or am I going to need to get down into the VBA?
Oct 5 '07 #1
3 1612
mlcampeau
296 Expert 100+
Count doesn't let you have a condition, but DCount does.
Expand|Select|Wrap|Line Numbers
  1. =DCount("[FieldName]","TableName","[FieldName]=True")
(Note that the syntax in the condition portion may be wrong...I'm still learning when to use quotes and such in this function)
You could also try something like this:
Expand|Select|Wrap|Line Numbers
  1. =Sum(IIf([FieldName]=True,1,0))
Oct 5 '07 #2
Got it working. I knew how to do it in code, but this is a REALLY simple little project, so I wanted to just do it right there on the form. Thanks to a few other little nuances, it would have been a lot of extra work to do this stuff in code. Plus, I just wanted to know how to do it for future reference.

If anyone cares, I was also using the count to calculate a percentage, and the expression I put as the control source ended up looking like this -

=DCount("[FieldName]","QueryName","[FieldName]=True")/Count([FieldName])

Thanks for the help.
Oct 5 '07 #3
mlcampeau
296 Expert 100+
Got it working. I knew how to do it in code, but this is a REALLY simple little project, so I wanted to just do it right there on the form. Thanks to a few other little nuances, it would have been a lot of extra work to do this stuff in code. Plus, I just wanted to know how to do it for future reference.

If anyone cares, I was also using the count to calculate a percentage, and the expression I put as the control source ended up looking like this -

=DCount("[FieldName]","QueryName","[FieldName]=True")/Count([FieldName])

Thanks for the help.
I'm glad you got it to work! Thanks for posting your final solution!
Oct 5 '07 #4

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

Similar topics

0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.