Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Occurrences of A, B, C, D in Questions 1-20 in report layout 1

Status
Not open for further replies.

vbaprogammer

Programmer
Sep 16, 1999
59
US
I have created a report layout to display the number of times an answer (A, B, C, or D) are given to a particular question in a set of questions 1 to 20, multiple records.<br>
<br>
Sample desired layout:<br>
.........A....B....C....D<br>
Q1.......16...2....1....3<br>
Q2........9...2...16....5<br>
etc.<br>
<br>
Input screen:<br>
<br>
Q1....___....Q2....___....Q3....___ etc.<br>
<br>
I can get counts using Query<br>
Q1.........Q1<br>
DB1........DB1<br>
Group by...Count<br>
<br>
which produces<br>
<br>
Question 1 (dummy numbers)<br>
A....19<br>
B.....2<br>
C.....5<br>
D.....1<br>
<br>
I need the counts for multiple questions. Even though the query provides the counts for A, B ..., I can't extract them into the format desired.<br>
<br>
I also need them to display in the report as indicated above ('cause the client likes it).<br>
<br>
I can create some unsatisfactory results with one record and one question, but I can't figure out how to get the counts parsed so I can spread them across the page.<br>
<br>
So,<br>
<br>
Say 20 participants in the test<br>
20 questions<br>
<br>
.............A....B.....C....D<br>
Question 1...5....8.....2....5<br>
Question 2...3....9.....9....4<br>
Question 3...0...20.....0....0<br>
...<br>
Question 20 ...<br>
<br>
I have spent two days on this, and am suffering from serious &quot;senior moments&quot; and brain drain. Can anyone put me on the right track? Would appreciate it.<br>
<br>
Dan<br>

 
Although I tried crosstab several times, I couldn't get the results I wanted, either because my data won't work in that scenario, or I don't know how to do it properly.<br>
<br>
Dan
 
Well Instead of trying to write one massive query try breaking it down in sections.<br>
See if you can make a simple query that gives some of the results.<br>
I always start problems that way then build on them.<br>
<br>
<p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
 
I agree writing one massive query may not be the way to go, but I can only get results from one simple query.<br>
<br>
I can't seem to create more than one bit of information, from one question, from one set of participants.<br>
<br>
So what I need is how to reformat this information, duplicate it, and present it to the client so I have all 20 questions on the left and all counts of answers in columns on the right.<br>
<br>
My file structure is:<br>
RegistrantID<br>
Question1<br>
Question2<br>
Question3<br>
... etc.<br>
<br>
With Question 1-20 containing either &quot;A&quot;, &quot;B&quot;, &quot;C&quot;, or &quot;D&quot;<br>
<br>
With future records totalling about 3,500.<br>
<br>
Perhaps it has been started completely wrong.<br>
<br>
Any help you can provide would be appreciated (or perhaps directions to some excellent training (as I feel out of my league on this one).<br>
<br>
Dan
 
Do you need to stay with that structure? Using that, the crosstab query wouldn't give you what you want in one step. It would work in one step with a structure of: <br>
<br>
RegistrantID<br>
QuestionNumber<br>
Answer<br>
<br>
Using QuestionNumber as your Columns. You might consider using this structure as it would be more flexible for analysis. A simple (manual) way change your structure is to set up a new table, and run an append query from your existing table. You'd run the query 20 times, each time just changing the Question/Column. Of course you wouldn't want to if you need to keep gathering data in your old format...<br>
<br>

 
Well, this may be &quot;cheating&quot;, but here is a piece of code that will do the job for you...from the way you describe it.<br>
<br>
First, this assumes that your table is as you described it, with the fields as &quot;Q1&quot; thru &quot;Q20&quot; for the question values, and that there is a row for each respondent. It also assumes that the values are &quot;A&quot; - &quot;D&quot;. In my sample code, I have assumed the name of this table is &quot;Questions&quot;. You can change that, obviously.<br>
<br>
You need to create another simple table...I called it QSummary. It has 5 fields:<br>
<br>
Q Text<br>
A Number<br>
B Number<br>
C Number<br>
D Number<br>
<br>
After executing the attached code, this new table will be filled with the sums of the A's - D's for the questions, and the field named 'Q' will be the text values &quot;Q1&quot; - &quot;Q20&quot;. The, just create a report....<br>
<br>
Good luck!<br>
<br>
Larry Woods<br>
<A HREF="mailto:larry@lwoods.com">larry@lwoods.com</A><br>
<br>
P.S. If you don't know how to execute the code, send me an email and I'll walk you through it.<br>
<br>
<br>
Code:<br>
<br>
<br>
<br>
<br>
<br>
<br>
Option Compare Database<br>
Option Explicit<br>
<br>
Public Sub LoadQ()<br>
Const QCOUNT As Integer = 20<br>
Dim Q(1 To QCOUNT, 1 To 4) As Long<br>
Dim intQIndex As Integer<br>
Dim intADIndex As Integer<br>
Dim strAD As String<br>
Dim rs As Recordset<br>
Set rs = CurrentDb.OpenRecordset(&quot;Questions&quot;)<br>
Do While Not rs.EOF<br>
For intQIndex = 1 To QCOUNT<br>
strAD = rs(&quot;Q&quot; & intQIndex)<br>
Select Case strAD<br>
Case &quot;A&quot;<br>
intADIndex = 1<br>
Case &quot;B&quot;<br>
intADIndex = 2<br>
Case &quot;C&quot;<br>
intADIndex = 3<br>
Case &quot;D&quot;<br>
intADIndex = 4<br>
End Select<br>
Q(intQIndex, intADIndex) = Q(intQIndex, intADIndex) + 1<br>
Next intQIndex<br>
rs.MoveNext<br>
Loop<br>
rs.Close<br>
Set rs = CurrentDb.OpenRecordset(&quot;QSummary&quot;)<br>
For intQIndex = 1 To QCOUNT<br>
With rs<br>
.AddNew<br>
!Q = &quot;Q&quot; & intQIndex<br>
!A = Q(intQIndex, 1)<br>
!B = Q(intQIndex, 2)<br>
!C = Q(intQIndex, 3)<br>
!D = Q(intQIndex, 4)<br>
.Update<br>
End With<br>
Next intQIndex<br>
rs.Close<br>
Set rs = Nothing<br>
End Sub<br>

 
Larry,<br>
<br>
It worked like a charm. Of course, I had to modify my routines a little, but your code worked without glitch.<br>
<br>
You have saved me hours of frustration. I have been working on this now for an hour, and accomplished more in this one hour than both days of last weekend.<br>
<br>
Elizabeth -- Yes, I agree. However, the client provided the data and the format. I still have a lot to learn about crosstabs. Seems you have it down pat.<br>
<br>
Thank you all for your quick responses. You all have proven there is a lot to learn, and thanks for sharing your knowledge.<br>
<br>
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top