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

Major Crosstab

23
Hi there, I need a little help please.

I need to create the following report for a medical training school:

Course Name:..............................Course1........ .......................Course2
Subject Name:............Subject1....Subject2....Subject3. ......Subject4..Subject5
Date:...........................1/1..2/1....1/1..2/1..5/1....8/1..9/1............1/1......13/1..2/2
Periods for Student1:...5.....2.......1.....1.....8.......5... .2...............0...........3.....1
Periods for Student2:...5.....2.......3.....1.....8.......5... .2...............2...........3.....1
Periods for Student3:...0.....2.......3.....0.....8.......5... .2...............2...........3.....1
Periods for Student4:...5.....2.......3.....1.....0.......5... .2...............2...........0.....1

Background:
Input data comes from a register, keeping record of:
what subject was covered during each period of each day;
what students attended each of those periods.

The report is supposed to show the total number of periods that each student spent on each subject per day. The data is thus Sorted and Grouped by Course, Subject, Date and sum([periods]).

Problem:
The report needs to show the Course, Subject, Date as column headers and the Students' detail as row headers.
However, I cannot use the Course, Subject and Date as column headers in the crosstab query, since there might easily be more than 255 columns in the crosstab query - depending on the number of days to be included.

I am thus forced to use the student's details as column headers (since you will not have more that 255 students in a class) and to use the Course, Subject and Date detail as row headers.

How do I then print the data with the Course, Subject, Date detail as column headers and the Students as row headers?

At the moment I export to Excel; transpose the data and then print it in Excel. But this takes ages and you must do it over each time they need updated reports.

Any suggestions please???
Jul 1 '08 #1
7 1770
nico5038
3,080 Expert 2GB
This will require some tricking.
Create a field that's combining the Course, Subject, Date and prepares the crosstable fieldslike:
Expand|Select|Wrap|Line Numbers
  1. Select StudentID as Row, Course & " " & Subject & " " & Date as Header, 1 as CountValue from tblX
  2. WHERE Date between [StartDate] and [Enddate];
  3.  
You should test that the number of distinct "Header" values don't exceed 255 (better not > 150) to prevent dumps. (More Header rows would just imply more reports for more periods).

This query can be used as the basis for a crosstable query, but I did found out sometimes the parameter request fails :-(
In that case we'll need to create the query from code. How are your VBA skills ?

When you need this in a report a next set of (VBA) tricks will be needed...

Nic;o)

P.S. Best not to use [Date] as a fieldname as it's also an Access function....
Jul 1 '08 #2
Gerhard
23
Hi Nico.

Let me get this straight...

1. Are you saying that I don't have a choice, but to use the Course, Subject, Date combination as column header? In other words,,, there is no way to transpose the data in Access or VB.

2. So this means the report has to run several times until all Dates have been included. How would you do this?

3. In the report itself, how do I check the value of the column headings. E.g. if I use the CourseID in the column heading, how do I extract it in the report - so that I can use it to look up the Course's description as well?

Regards
Gerhard
Jul 2 '08 #3
nico5038
3,080 Expert 2GB
Hi Gerhard

The response is marked by ==>""

1. Are you saying that I don't have a choice, but to use the Course, Subject, Date combination as column header? In other words,,, there is no way to transpose the data in Access or VB.
==> Access will only allow ONE field to be used for the header column, thus the concatenation is the only way to combine them.

2. So this means the report has to run several times until all Dates have been included. How would you do this?
==> Only as many times as you need periods of some 150 days to cover the needed period. Personally I would probably create monthly reports per Course, thus limiting the width. A 250 column reports doesn't look pritty...

3. In the report itself, how do I check the value of the column headings. E.g. if I use the CourseID in the column heading, how do I extract it in the report - so that I can use it to look up the Course's description as well?
==> The concatenated field becomes the column heading, thus the value should show as required. Problem will be the assignment of the column to the query field, as Access will name the fields after the column value.
Thus VBA code is needed to place the fields "relatively"

Nic;o)
Jul 2 '08 #4
Gerhard
23
Hi Nico

The response is marked by ***>""

3. In the report itself, how do I check the value of the column headings. E.g. if I use the CourseID in the column heading, how do I extract it in the report - so that I can use it to look up the Course's description as well?
==> The concatenated field becomes the column heading, thus the value should show as required. Problem will be the assignment of the column to the query field, as Access will name the fields after the column value.
Thus VBA code is needed to place the fields "relatively"

***> I cant use the Course Description as column heading since it is to long. I must thus use the CourseID and use it in the report to retrieve the Course Description.
How do I refer to the column name in the report in order to retrieve the CourseID?

Gerhard
Jul 2 '08 #5
nico5038
3,080 Expert 2GB
You'll need some code for that. I used the following code myself in a similar case. To start, doing this you need to place the fields "coded" in the report.
The column headings should be called "lblCol1", "lblCol2", "lblCol3", etc.
The "detail" fields should be called "Col1", "Col2", "Col3", etc.

The report query has two rowheader columns and a Total column, therefor the first field is effectively column 4 (count starts at 0 so I used intI=3) but this could differ for you.

Make sure that the number of Columns is not bigger as the number placed. The programcode has no protection against that !

The OpenReport code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2. Dim intI As Integer
  3.  
  4. Dim rs As Recordset
  5.  
  6. Set rs = CurrentDb.OpenRecordset(Me.RecordSource)
  7.  
  8. 'Place headers
  9. For intI = 1 To rs.Fields.Count - 1
  10. Me("lblCol" & intI - 1).Caption = rs.Fields(intI).Name
  11. Next intI
  12.  
  13. 'Place correct controlsource
  14. For intI = 13 To rs.Fields.Count - 1
  15. Me("Col" & intI - 1).ControlSource = rs.Fields(intI).Name
  16. Next intI
  17.  
  18. End Sub
  19.  
The report query has one rowheader column, therefor the first field is effectively column 1 (count starts at 0) but it could differ for you when using multiple rowheaders.
Getting the Course description can be done in the "header loop" with a DLOOKUP() function.

Nic;o)
Jul 2 '08 #6
Gerhard
23
Thanx Nico.

That will help.

Regards
Gerhard
Jul 3 '08 #7
nico5038
3,080 Expert 2GB
Keep me posted and don't hesitate to ask when you get stuck :-)

Nic;o)
Jul 3 '08 #8

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

Similar topics

3
by: Darleen | last post by:
I am seeking conceptual here on how to get started with a "3D Matrix" in Access. We run a training center which holds multiple classes in multiple cities at multiple times. So I need to create a...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
2
by: Sherman H. | last post by:
I have a few questions for crosstab and popup form questions: 1. I created a crosstab as follows: IT Financial Operation John 21 22 ...
4
by: Judy | last post by:
I'm using Access 2003 and was wondering if it is possible to have a paramater selection within a crosstab query so that I wouldn't need to build a new table. I have a select query that I'm using...
7
by: newguy | last post by:
I am trying to get the totals of a table by client by type of income. This query will get what I am looking for with each unique combination as a row: SELECT Sales.Client, BillCode.Type,...
8
by: Penny | last post by:
(Access 2003 Multiuser Split DB, Windows XP Pro) Hi All, I would really appreciate just some basic tips on how to make a Crosstab Form based on a Crosstab Query. The query always has the same...
14
by: Tina | last post by:
My employer tracks productivity/performance of clinicians (how much they bill) each week, its averages for the month, and the 6 months. These averages are compared to their expected productivity....
13
by: salad | last post by:
Operating in A97. I didn't receive much of a response conserning Pivot tables in Access. Pivot tables are nice, but a CrossTab will work for me too. Using a Pivot table, one is actually...
4
by: m.wanstall | last post by:
I have a crosstab query that compiles data for Months of the year. I have a stacked select query on top of that crosstab query that uses the latest 2 months data and exports it to a fixed length...
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: 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: 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
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.