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

Need calulations to work with # of fields in a Report

Hello,
I have a situation in which each record on a report has 40 fields, any
one of which can contain a value of 'C', or 'I', or 'B'. I need to
create one calculated field on the report that will COUNT the number
of fields with a value of 'C'(and shows the integer result), and
another calculation that will take the COUNT of the fields with a
value of 'C' and divide that by the total number of fields. The second
calculation would be expressed as a percentage, allowing for two
decimal places.

The field names for the forty fields are Q1, Q2, Q3.....Q40. A sample
of the records would look like this:

StudentID Name Q1 Q2 Q3 Q4 #Correct %Correct
1234 John C C I B 2 50.00%

How would I accomplish this, and what event would the procedures be
assigned to in the report? The records in the report that requires the
calculations is in the detail section of the report, and the report
itself is a sub report located within the detail section of the main
report.

Thanks for your help!

CSDunn
Nov 12 '05 #1
3 1371
DFS
You need to write a function. If your report controls are labeled Q1, Q2,
.... it will be much easier. If not, you'll have to type each report control
name in the code.

This code goes in the Detail_Format event of the subreport containing the
Question answers:
Public Sub Detail_Format()

'GET COUNTS
for i = 1 to 40
if me("Q" & i) = "C" then
countC = countC + 1
elseif me("Q" & i) = "I" then
countI = countI + 1
elseif me("Q" & i) = "B" then
countB = countB + 1
endif
next i

'SHOW C COUNT
Me.txtCountC = countC

'SHOW C PERCENT (FORMAT THE FIELD ON THE REPORT)
Me.txtPercentC = countC / 40

End Sub
As you can see, if your fields aren't named with an increasing number,
you'll have a big headache.


"CSDunn" <cd***@valverde.edu> wrote in message
news:80**************************@posting.google.c om...
Hello,
I have a situation in which each record on a report has 40 fields, any
one of which can contain a value of 'C', or 'I', or 'B'. I need to
create one calculated field on the report that will COUNT the number
of fields with a value of 'C'(and shows the integer result), and
another calculation that will take the COUNT of the fields with a
value of 'C' and divide that by the total number of fields. The second
calculation would be expressed as a percentage, allowing for two
decimal places.

The field names for the forty fields are Q1, Q2, Q3.....Q40. A sample
of the records would look like this:

StudentID Name Q1 Q2 Q3 Q4 #Correct %Correct
1234 John C C I B 2 50.00%

How would I accomplish this, and what event would the procedures be
assigned to in the report? The records in the report that requires the
calculations is in the detail section of the report, and the report
itself is a sub report located within the detail section of the main
report.

Thanks for your help!

CSDunn

Nov 12 '05 #2
Thanks for your help. I failed to mention that some of the fields will
be NULL, and my percentage calculation will not be correct if I always
use 40 as a denominator.

How would I reconfigure the following code to account for "Q" fields
that are NULL, and exclude them from at least my percentage calculation?

'GET COUNTS
For i = 1 To 40
If Me("Q" & i) = "C" Then
countC = countC + 1
ElseIf Me("Q" & i) <> "C" Then
countC = countC + 0
End If
Next i

'SHOW C COUNT
Me.txtCountC = countC

'SHOW C PERCENT (FORMAT THE FIELD ON THE REPORT)
Me.txtPercentC = 100 * (countC / 40)
End Sub

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3
I think I have what I needed now:

'GET COUNTS
For i = 1 To 40
If Me("Q" & i) = "C" Then
CountC = CountC + 1
ElseIf Me("Q" & i) = "I" Then
CountI = CountI + 1
ElseIf Me("Q" & i) = "B" Then
CountB = CountB + 1
End If
Next i

'SHOW C COUNT
Me.txtCountC = CountC

'SHOW C PERCENT (FORMAT THE FIELD ON THE REPORT)
Me.txtPercentC = 100 * (CountC / (CountC + CountI + CountB))

I haven't tested this in the case where one of the values might but
NULL, but I don't see why it would not work.

Thanks again for your help!
CSDunn

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: JC Mugs | last post by:
Problem: Have a data entry form that enters new records that we need to print invoices from when the form is completed. I expect to be able to place a command button on the form and print the...
1
by: Ellen Manning | last post by:
I've got a report with a subreport linked on fund number. The subreport returns 2 columns of dollar amounts, both current and YTD, by object code for the selected fund number. The user can select...
0
by: Neal | last post by:
Hi, I have been trying to get various types of data to print out on a single report. The following kinds of data are to be included: 1) A company logo 2) Company info, based on an RTF file...
1
by: Brad | last post by:
Thanks for taking the time to read my question. I have a table of data that has Date, Data and Category. I need to show, in a report, each Categories Data by Date. The Date has to be it's own...
1
by: mike11d11 | last post by:
For some reason I'm getting no data populating in my crystal report. I built my crystal report off my dataset in my project, and I fill the dataset when opening the main form, and count the...
0
by: mike11d11 | last post by:
I have a form with a dataset that contains account records in one table and another table that contains transactions for accounts that are in the other table. I'm trying to create a report based...
2
by: marklawford | last post by:
I've been prototyping a reporting solution using XSLT and Java to transform a number of XML files into different formats (PDF and CSV mainly). The XML comes from a legacy system where a number of...
6
by: pukhton | last post by:
Hello~ Just a quick question about Access Reports. I want to have a form for user where they will have two textbox and one combo box to pick from and run the query based on that. 1 txtbox is...
6
by: martin DH | last post by:
**Urgent Need** I'll throw out the basics and any assistance is very, very, very much appreciated! Access 2003 on XP On a form (frmMain) is an option group of check boxes (ReportFrame) from...
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...
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,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.