Queries :: Fixed Heading Names In Crosstab With Dynamic Columns
Jul 3, 2014
I'm trying to run a query which fetches only the last 2 years of data for a given region from a table with several years worth of data (there are year, region, sector and rank columns among others). The region is passed into the query from a combobox from Form1.
The first problem was that some regions have up-to-date data and some not so much e.g. for Europe the "last 2 years" mean 2012,2013 for Asia its 2011,2012. In order to deal with this I've created a crosstab query which works well except for one thing - because the columns are dynamic (dependant on the region) the column headings change as well.
And here comes my question, how can i fix the column names to be e.g."Current Year" and "Prior Year" independent of the query fetching 2012,2013 or 2009,2010? I've tied different things with PIVOT... IN ... but with no luck.
Here's the sql for the query:
Code:
PARAMETERS [Forms]![Form1]![cmbRegion] Text ( 255 );
TRANSFORM min(DataTable.Rank)
SELECT DataTable.Region, DataTable.RegionalSector,
FROM DataTable
WHERE (((DataTable.Region)=Forms!Form1!cmbRegion))
I've made a crosstab query and would like to use it to create a subreport. In the column headers I have names of courses. Courses can be added or removed. How can I make a crosstab report with dynamic columns?
I've setup some crosstab queries with good success and set column headings that appear with blank spaces when there's no data as expected, but I have 1 report that is formatted with set row headings (its a specifically formatted report that i need to produce, that i can't just change).So I need to basically do the same but with the row headings set (I have got the crosstab working, just not showing the rows with no data as yet).
I am building a database which tracks tasks assigned to employees. I want to have one of my forms displaying a view which shows at a glance which tasks are assigned to whom at what times of the day, with a click opening a task for editing. My current attempt is to create a crosstab query with the employees as the column headings ("dynamic crosstab" query) and a table of time values for the hours of the day providing the row headings, with the task as the value.
I then created a form based on the query with Datasheet view as the default view (apparently necessary to set properties/event handlers to query values. I got the idea from the Northwind sample database) However, the form fields do not update to reflect changes to the employee list and therefore the onClick handlers are not applied to newly added employees. What to do, besides for programmatically setting the event handlers?
Being an amateur at Access, I've only recently realized that you can force column headings for crosstab queries, by typing those headings into the properties of the field selected as the column. But can you do the same for ROWS?
My data concerns patients of a specific type and the times of day they show up at our A&E (ER). I've grouped these by hour and now I want to crosstab them by day of week. But if there aren't any between say 3am and 5am, those hours don't show in the query, which is screwing up a pre-formatted report I have.
I've found some assistance on other threads..... http://www.access-programmers.co.uk/forums/showthread.php?t=92471 http://www.access-programmers.co.uk/forums/showthread.php?t=83820 .....but to be honest I didn't really follow it.
Is there an easy solution? If not, it's not a huge problem and I can "fudge" it once a month, offensive as that must sound to you professional types!
I have a crosstab query that groups by week to obtain columns for monday to sunday. Is there a way to obtain the actual dates that these columns represent?
Record Primary Key: ID_Wells..The TxtFedStCo has Fed, St, Co, ... in one field - and a Dt_Apd_Sub (date submitted) .There can be zero or many dates submitted for each Fed or State.
Objective: If A Fed has (1 or many) date submitted AND A St has (1 or many) date submitted Condition is TRUE
How do I get to the next step? The reason for doing this in SQL is to prototype in Access, then move this over to TSQL later.
I am making a classic sales over time crosstab query.
Rows: Customers Columns: Sale months
Sales date is defined by the ETD of the order.
However, with the simple Format([ETD],"yyyy-mm") I get regular months, but I need to adjust the months to be between the 21st and 20th rather than 1st to 31st(30th).
August would be 7/21/2013 to 8/20/2013 September 8/21/2013 to 9/20/2013
I then created a 2nd select query with inner joins to join both crosstab queries on similar fields (activity & projectname).
SELECT QUERY 2: projectname, activityname, employeename (totalhoursworked as value), employeename (calculatedcost as value)
It gives me this:
However, I want it like this:
Those employeename... refers to more employees being added after a period of time. Hence I want to know if I could use vba to generate a report every time a button is pressed on a form? I know how to link the form to the query.
I have a query that gives me a table with one column, say column A. I need to add 2 columns to the table and the coulmns will have fixed value. So I need to add column B and column C to my table and all rows in column B will have a fixed value and all rows in column C will have a fixed value.
What I have: Table with one column Column A a b c
What I need: Table with 3 columns: ColumnA Column B Column C a 12 14 b 12 14 c 12 14
The above table suits me well for data entry.For analysis reasons, I want it to have another table or query or something (let's call it "Teacher Info") that looks like this:
Is there any way that I could do this? I have been struggling with this for a while.Just so you know how this data is connected - At the moment, I have a form where I put in new Teacher information. I have a subform attached to that, where I put the student names and numbers. This way, the students are linked with their student #s, and each of them are linked to a teacher. Unfortunately, the table ("New Teacher Registration") that this creates looks like this:
id....Teacher Name 62...... Alice (+ tab).........A.........432 ...................B.........674 ...................C.........875 18.......Katie (+ tab).........D.........934 ...................E.........345 4........Dan (+ tab).........F.........134 ...................G.........734
I created the "Student Info" table (above) from this to work with data entry (drop-downs and such). Now I'd like to create a "Teacher Info" table (above) for analysis.
I have 12 months' worth of data that the user wants displayed on a crosstab report. I have no problem creating the crosstab query or subsequent report. However, the user wants to be able to select their own 12 month time period. So, my crosstab is based upon a make table query, that will allow the user to enter parameters. Now, my problem is that these 12 month column headers/data will change as the user enters different date ranges. How do I write the code that will allow me to pass these variables to the report? I'm using 97. Thanks!
I am using the following cde to generate a Dynamic Crosstab Report. I can get the column labels to work but Ican't get the values to appear in the detail section all I get is #Name? I am using the following code in the report
Private Sub Report_Open(Cancel As Integer) Dim rst As DAO.Recordset Dim db As DAO.Database Dim i As Integer Dim j As Integer Set db = CurrentDb Set rst = db.OpenRecordset("select * from test2") rst.MoveFirst j = 0 i = 0 For i = 0 To rst.Fields.Count - 1 If rst.Fields(i).NAME Like "*test" Then GoTo skip_it j = j + 1 Select Case j Case 0 Me.Field0.ControlSource = rst.Fields(i).NAME Case 1 Me.Field1.ControlSource = rst.Fields(i).NAME Case 2 Me.Field2.ControlSource = rst.Fields(i).NAME Case 3 Me.Field3.ControlSource = rst.Fields(i).NAME Case 4 Me.Field4.ControlSource = rst.Fields(i).NAME Case 5 Me.Field5.ControlSource = rst.Fields(i).NAME Case 6 Me.Field6.ControlSource = rst.Fields(i).NAME Case 7 Me.Field7.ControlSource = rst.Fields(i).NAME Case 8 Me.Field8.ControlSource = rst.Fields(i).NAME Case 9 Me.Field9.ControlSource = rst.Fields(i).NAME End Select skip_it: Next i rst.Close Set rst = Nothing End Sub Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer) Dim rst As DAO.Recordset Dim db As DAO.Database Dim i As Integer Dim j As Integer Set db = CurrentDb Set rst = db.OpenRecordset("select * from test2") rst.MoveFirst j = 0 i = 0 For i = 0 To rst.Fields.Count - 1 If rst.Fields(i).NAME Like "*test" Then GoTo skip_it j = j + 1 Select Case j Case 0 Me.Label0.Caption = rst.Fields(1).NAME Case 1 Me.Label1.Caption = rst.Fields(i).NAME Case 2 Me.Label2.Caption = rst.Fields(i).NAME Case 3 Me.Label3.Caption = rst.Fields(i).NAME Case 4 Me.Label4.Caption = rst.Fields(i).NAME Case 5 Me.Label5.Caption = rst.Fields(i).NAME Case 6 Me.Label6.Caption = rst.Fields(i).NAME Case 7 Me.Label7.Caption = rst.Fields(i).NAME Case 8 Me.Label8.Caption = rst.Fields(i).NAME Case 9 Me.Label9.Caption = rst.Fields(i).NAME End Select skip_it: Next rst.Clone Set rst = Nothing End Sub
What else do I need to do to get data in the detail section In anticipation
I’m trying to create a report with dynamics columns generated by a crosstab query. I have set 4 unbound text boxes for header and detail sections on the report. The column heading from the crosstab query could have 1(Column), 2 or 3 different values, which will be my heading in the report. I want to be able to show 1(Column) if it has a valued and hide the rest 2, and 3 heading. Now column 4 headers will be my Total heading as well for values, which will be coming from the sum of 1,2 and 3 if they happened to have values.
Can anyone help on this please, and let me know if I should bring some more information to you guys.
I have a crosstab Query as the source for my report, of course the issue is the column headings on the report. I have Purchasers as a row heading, Year as a row heading, Month/Year as a row heading, Meter as a column heading, PaidMCF as Value and, a total as a Row heading. My issue is feeding the column headings on my report with the meter names.
Purchaser 1 has 23 meters attached Purchaser 2 has 1 meter attached Purchaser 3 has 6 meters attached Purchaser 4 has 2 meters attached Purchaser 5 has 16 meters attached Purchaser 6 has 11 meters attached.
Hi, I wish to use the results of a crosstab query in another query which will make table. The trouble is the field names are not always the same in the crosstab. The results are coming from a normalised table so if there are no records for a particular field then that field will no appear in the crosstab.
I need to make my 'make table query' (qryTabletImport_CollarMakeStaging) account for the missing fields names when it tries to make the new table. Since I have made the make table query with all availble field names I get this error when some are not present.
<the jet engine doesnot recognise 'qryTabletImport_CollarConvert.Hours' as a field name or expression>
(because the field Hours doesn't have any data in the normalised table)
i want this to be editable. how would i do this using access form, or do i have to wrtite VBA code
PLUS i want the form to automatially have new records when i add for example a student, with ID 10011 OR if i add new records for a different date say 11/11/2006, then i want that to be viewd on the form just like the 21/09/2006 and the 04/11/2006.
please help :) been looking for a solution for long time.
This code runs to the set frm part then i get a type mismatch? ive tried a few different things and still nothing?
Code:
Private Sub Report_Open(Cancel As Integer) ' Create underlying recordset for report using criteria entered in ' EmployeeSalesDialogBox form. Dim intX As Integer Dim qdf As QueryDef Dim frm As Form ' Set database variable to current database. Set dbsReport = CurrentDb
I have made a cross-tab query which works fine. I also have made a report which is based on this cross-tab query. Due to nature of the cross-tab query the Value column(s) is dynamic. The report I made is based on all available data types (columns). The report works if all data type is available but the report fails if some of the data types are not available (i.e columns are missing due to not having any value or data). I hope I am explaining this correctly,
Is there a way I can use expressions in the report to place a conditional clause that if the Control Source doesn't exist place a Null or 0 in the report or in its place.
:D I am trying to create a CrossTab query from a table of expenses:
tblExpenses: PropertyID ExpenseType Amount
There are many kinds of Expense Types. I want to use ExpenseType as the column header, BUT I want there to be 3 categories "Rent Expense," "Taxes," and "Other."
HOW do I group all expense types <> "Rent Expense" and "Taxes" in the third column?
I can get a comprehensive query with many columns, or set criteria to get just "Rent Expense" and "Taxes" columns, but I cannot get the 3 columns.
I am trying to make a new form with the same info as another but in a different view for easily updatable forms/reports. The current table i have looks like this:
Company Product Market Available? 1................1................2..........yes 1................5................2...........yes 2................1................1...........yes 2................2................6............yes
etc... with the numbers linked to tables with the actual name.
what i want to do is make a table with field names that correspond the different products so that it looks like this:
Ive played around with crosstab queries but I'm not getting the results i want. Is there any way to have this new table linked to my first table so that if theres a new product # entered it will automatically make a new column on the new table and fill it in? Let me know if this is too confusing, Thanks for your help.