If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > How to count multiple text boxes in a Report

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-10-10, 16:17
Brian62 Brian62 is offline
Registered User
 
Join Date: Nov 2010
Posts: 24
How to count multiple text boxes in a Report

have a report where I am trying to count all the text boxes which comprises of about 8o. I want to separate them by Yes, No and N/A. I tried a few different options and none have worked in Control Source.

Example1: =Count(IIf([RDStudyAuditSectionA.Doc #12-5]+[RDStudyAuditSectionA.Email Corrospondence]+[RDStudyAuditSectionA.Doc #2]="Yes",0))

Example2=Count(IIf([Doc #12-5]+[Email Corrospondence]+[Doc #2]="Yes",0))

Example3=Count(IIf([Doc #12-5],[Email Corrospondence],[Doc #2]="Yes",0))

The formula is set in the report footer. The information is coming from a query with 10 different tables linked to one query which the Report operates off of.

I have tried it on the query side but I can't figure it out there as well.

Attached is the DB. Look at the center column. That is the one I am trying to count for each category (Yes, No and N/A).

Thanks!
Attached Files
File Type: zip Study1.zip (82.2 KB, 12 views)
Reply With Quote
  #2 (permalink)  
Old 11-12-10, 00:25
HiTechCoach HiTechCoach is offline
Registered User
 
Join Date: May 2010
Posts: 600
I don't understand what your examples are trying to do.

Please explain in more detail what you are trying to count().
__________________
Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
Microsoft MVP - Access Expert
BPM/Accounting Systems/Inventory Control/CRM
Programming: Nine different ways to do it right, a thousand ways to do it wrong.
Binary--it's as easy as 1-10-11

Last edited by HiTechCoach; 11-12-10 at 11:24.
Reply With Quote
  #3 (permalink)  
Old 11-12-10, 09:39
Brian62 Brian62 is offline
Registered User
 
Join Date: Nov 2010
Posts: 24
I am trying to count the middle column in the report. Each text box is different than the others and need to find a way add all of them. There is approximately 80 different cells. I hope that helps.
Reply With Quote
  #4 (permalink)  
Old 11-12-10, 11:36
HiTechCoach HiTechCoach is offline
Registered User
 
Join Date: May 2010
Posts: 600
Not really. You did not explain want any of the example are attempting to do. The logic in your example does not seam correct or make sense. Without a better understanding of exactly what you are trying to do, I can not offer any suggestions.

Since we know nothing about your database or what you are doing you need to give enough details that we understand exactly what you are doing.

It has been my experience in 30+ years of software development that if you can not explain the steps of what you are doing to another human then it will be difficult to translate the steps into code that will give you the desired results.
__________________
Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
Microsoft MVP - Access Expert
BPM/Accounting Systems/Inventory Control/CRM
Programming: Nine different ways to do it right, a thousand ways to do it wrong.
Binary--it's as easy as 1-10-11
Reply With Quote
  #5 (permalink)  
Old 11-12-10, 11:49
Brian62 Brian62 is offline
Registered User
 
Join Date: Nov 2010
Posts: 24
The database is attached in an earlier post. I don't know how to explain it better than I already have. If you look at the report then look at the center column (test box) which are all different names coming from a query with about 80 different column names. As the fields populate in the center column of the report then I want the report footer to give me a total Yeses, No's and N/A from all the different text boxes. Once I figure out the Yeses I can change the formula for the other two.

I hope this helps but I'm not sure if I explained it any better.
Reply With Quote
  #6 (permalink)  
Old 11-12-10, 13:25
HiTechCoach HiTechCoach is offline
Registered User
 
Join Date: May 2010
Posts: 600
Unfortunately I am not at a place where I have a test machine that will provide a safe environment to look at you attachment.

Note: Nothing personal toward you, but I am very cautious at looking at attachments from unknown sources. I am overly very cautious of emails and posts that are very brief and say just lookmy attachment for details. This is a common way to deloy malicious stuff.


There seams to be several issues with you examples. I will pick one.

Code:
=Count(IIf([Doc #12-5]+[Email Corrospondence]+[Doc #2]="Yes",0))
The IIF using has three parts.

The first part needs to evaluate to true or false.

What is the result of this calculation?
Code:
[Doc #12-5] + [Email Corrospondence]+ ([Doc #2]="Yes")
What is the data type for each of these fields?
[Doc #12-5]
[Email Corrospondence]
[Doc #2]

I would think that [Doc #2] is a trying that can have the Values "Yes" or "No" or possible some other string. Is this correct?

Does ([Doc #2]="Yes") evaluate to a true or false correctly?
__________________
Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
Microsoft MVP - Access Expert
BPM/Accounting Systems/Inventory Control/CRM
Programming: Nine different ways to do it right, a thousand ways to do it wrong.
Binary--it's as easy as 1-10-11
Reply With Quote
  #7 (permalink)  
Old 11-12-10, 14:02
Brian62 Brian62 is offline
Registered User
 
Join Date: Nov 2010
Posts: 24
I understand your reluctance.

Answer to question 1: If 2 out of the three give me 2 yeses than 2 would be the total I am looking for. Currently gives me an #error. How would I rewrite the formula to show true or false for the first part?

Answer to question 2: The fields are set to text in the table. Yes the data type can be any other string but I only use Yes, No and N/A in a drop down box in a form.

Is this the information you are looking for?

Thanks!!
Reply With Quote
  #8 (permalink)  
Old 11-13-10, 07:20
Sinndho Sinndho is online now
Registered User
 
Join Date: Mar 2009
Posts: 3,446
Like Boyd, I'm not sure to understand your question clearly.

If what you try to achieve is counting the number of occurences of a determined value in one or several fields, this can mean counting the same number of occurences in one or several columns in the datasource (table or query) of the report.

This can be done in SQL:
Code:
SELECT COUNT (*) AS Total
FROM <Data Source>
WHERE <Column> = '<Value>';
For counting in several columns this becomes:
Code:
SELECT COUNT (*) AS Total
FROM <<Data Source>
WHERE (<Column1> = '<Value>') 
     OR (<Column2> = '<Value>') 
     OR ...;
You could also merge the different column using a UNION query, then use a COUNT and a condition on the resulting data set:
Code:
SELECT Count(*) AS Total
FROM [SELECT <Column1> AS x FROM <Data Source>
UNION
SELECT <Column2> AS x FROM <Data Source>
UNION
SELECT <Column3> AS x FROM <Data Source>
UNION
SELECT <Column4> AS x  FROM <Data Source>]. AS Merged_Alias
WHERE Merged_Alias.x = '<Value>';
With 80 columns you would probably quickly reach the maximum level of complexity that Access can process in a SQL expression, so you would have to use several partial queries and sum them together but this can be done.
__________________
Have a nice day!
Reply With Quote
  #9 (permalink)  
Old 11-13-10, 10:41
HiTechCoach HiTechCoach is offline
Registered User
 
Join Date: May 2010
Posts: 600
I did finally get to a test computer where I could look at your attachment.

The first this that I notices what that the database really is not properly normalized. What you are wanting would be a whole lot easier to do if the tables were properly normalized.

TIP: You should avoid using object names as data.

If designed properly you should be able to add or remove new items without modifying the table design. For example: adding a new a Doc # should not require you to modify the design of the table. This would also be true for Audit Sections. You should be able to add a new Audit section without adding a new table.

As Sinndho suggested, you could use a UNION query to properly normalize your data as a bandage. You might hit some limits so I would recommend running a bunch of queries to append the data into a properly normalized table that you can use as the record source for your report.

Before attempting this report I would urge you to redesign your tables using the rules of data normalization. Are you allowed to redesign the tables?
__________________
Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
Microsoft MVP - Access Expert
BPM/Accounting Systems/Inventory Control/CRM
Programming: Nine different ways to do it right, a thousand ways to do it wrong.
Binary--it's as easy as 1-10-11
Reply With Quote
  #10 (permalink)  
Old 11-15-10, 15:00
Brian62 Brian62 is offline
Registered User
 
Join Date: Nov 2010
Posts: 24
I took what you gave me and this is what I tried with no luck.

SELECT Count(*) AS Total
FROM [SELECT 'Doc #2' AS x FROM <RDStudyAuditSectionA]
UNION
SELECT ['Doc #25' AS x FROM <RDStudyAuditSectionA]
UNION
SELECT ['Doc #28-5' AS x FROM <RDStudyAuditSectionA]
UNION
SELECT ['Doc #30' = AS x FROM <RDStudyAuditSectionA] AS Merged_Alias
WHERE Merged_Alias.x = '<Value>';

I also tried this and got a total of 10 when it should be a total of 18 for the yeses.

SELECT Count(*) AS Total
FROM RDStudyAuditSectionA
WHERE ((('Doc #25')='Value')) & ((('Doc #25')=Yes) & (('Doc #2')='Value')) & ((('Doc #2')=Yes));

Is there something that I am missing?? I tried various scripts but couldn't get anything to work. Thanks!

Last edited by Brian62; 11-15-10 at 15:09. Reason: More info.
Reply With Quote
  #11 (permalink)  
Old 11-15-10, 15:25
HiTechCoach HiTechCoach is offline
Registered User
 
Join Date: May 2010
Posts: 600
I would highly user you to NOT use spaces or non-alpha or numeric characters.

For example the field name Doc #25 needs to be wrapped with [ and ] like this [Doc #25]

Wrapping the field name with apostrophes (') ccreates a string. 'Doc #25' is a literal string NOT a field name.


So you would need to use something like this:

You also wooudl not use & between the conditions in the Where. Use And or OR

Code:
SELECT Count(*) AS Total
FROM RDStudyAuditSectionA
WHERE ((([Doc #25]='Value')) Or ((([Doc #25]='Yes') Or (([Doc #2]='Value'))or ((([Doc #2]='Yes'));
Is 'Value' a valid option?


If you wanted it were at least one is YES then I woudl use:

Code:
SELECT Count(*) AS Total
FROM RDStudyAuditSectionA
WHERE  (([Doc #25]='Yes') Or ([Doc #2]='Yes') );

If you wanted it were BOTH are YES then I would use:

Code:
SELECT Count(*) AS Total
FROM RDStudyAuditSectionA
WHERE  (([Doc #25]='Yes') and ([Doc #2]='Yes') );
__________________
Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
Microsoft MVP - Access Expert
BPM/Accounting Systems/Inventory Control/CRM
Programming: Nine different ways to do it right, a thousand ways to do it wrong.
Binary--it's as easy as 1-10-11
Reply With Quote
  #12 (permalink)  
Old 11-15-10, 15:49
Brian62 Brian62 is offline
Registered User
 
Join Date: Nov 2010
Posts: 24
I tried this code you suggested (#3) with one additional doc # for a test.

SELECT Count(*) AS Total
FROM RDStudyAuditSectionA
WHERE (([Doc #25]='Yes') and ([Doc #2]='Yes') and ([Doc #36]='Yes') );

The total for yeses in those three should be 25 but it is showing 7. It's not counting correctly. The more columns I add the smaller the number gets.

Value is not a valid option that I can get to work.
Reply With Quote
  #13 (permalink)  
Old 11-15-10, 15:57
HiTechCoach HiTechCoach is offline
Registered User
 
Join Date: May 2010
Posts: 600
For the following:

Code:
SELECT Count(*) AS Total
FROM RDStudyAuditSectionA
WHERE (([Doc #25]='Yes') and ([Doc #2]='Yes') and ([Doc #36]='Yes') );
This only counts the number of record where ALL three fields ARE EQUAL to YES.

Is that what you want?
__________________
Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
Microsoft MVP - Access Expert
BPM/Accounting Systems/Inventory Control/CRM
Programming: Nine different ways to do it right, a thousand ways to do it wrong.
Binary--it's as easy as 1-10-11
Reply With Quote
  #14 (permalink)  
Old 11-15-10, 16:03
Brian62 Brian62 is offline
Registered User
 
Join Date: Nov 2010
Posts: 24
No. I need to have a total of all the yeses in all the columns. I will be adding more columns once the totals come out correctly.

Doc #2: has 9 Yes, 1 No
Doc #25: has 8 Yes, 1 NO, 1 N/A
Doc #36: Has 8 Yes, 2 No

Total should be 25. I hope this helps! Thanks!!
Reply With Quote
  #15 (permalink)  
Old 11-15-10, 16:04
HiTechCoach HiTechCoach is offline
Registered User
 
Join Date: May 2010
Posts: 600
I have been tryhing to figure out wehat you want.

Previously you stated
Quote:
Answer to question 1: If 2 out of the three give me 2 yeses than 2 would be the total I am looking for.
After some pondering on the above, I have a few questiosn for you.

Are you wanting to total number of Yes's in a sinlge record?

or

Are you wanting the number of YES's for a single field in all records?
__________________
Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
Microsoft MVP - Access Expert
BPM/Accounting Systems/Inventory Control/CRM
Programming: Nine different ways to do it right, a thousand ways to do it wrong.
Binary--it's as easy as 1-10-11
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On