473,289 Members | 2,106 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,289 software developers and data experts.

Generating a report over a cross-tab query

I have yet a new issue that is the only factor stopping me from adding on the last feature to the database; all help is very much appreciated!

In my database is are two tables: one for inserting contact information and employee status, and the other documenting work history. I created a query that contains only the most recent data entered and from that query I created a cross-tab query that reads the data in the query and returns the list of all the names as the row headers, the status as the column header, and the totalCount as the value. Whenever the cross-tab is run, it works as it's suppose to by supplying all the names in the Y-axis, all the status types in the X-axis, and the count of each type in the columns. When a user modifies the status for the employee the query is updated, sometimes the status may change or a new status type is added to. For example the query may return:

Ex. 1
----------------------------------------------------------------------------------------
Contacted Accepted Declined
John 1
Mary 1
Adam 1
----------------------------------------------------------------------------------------

Then if a new name is added to the table the cross-tab query is updated:
Ex. 2
----------------------------------------------------------------------------------------------------
Contacted Accepted Declined Offer Extended
John 1
Mary 1
Adam 1
Sarah 1
---------------------------------------------------------------------------------------------------

Now that all works. The problem is that when it comes time to making a report I'm lost on about how to make the report dynamic in the sense of having it display the data in Ex. 1 but when new information is added having it updated to display the data in Ex. 2 automatically. Eventually I would like to add subtotals in the report to show the current number of status_types there are for example:

Contacted Accepted Declined Offer Extended
John 1
Mary 1
Adam 1
Sarah 1
Joseph 1
Sally 1
Eric 1
---------------------------------------------------------------------------------------------------
Subtotal: 2 1 2 2


I assume I will have to do some VBA and perhaps SQL magic but I don't know about how to do that. Can anyone provide me wuth some code snippets (if any) or direct me in a new direction from how I am approaching this?
Mar 26 '07 #1
5 2612
My last posting wasn't formatted correctly but hopefully this works:

I have yet a new issue that is the only factor stopping me from adding on the last feature to the database; all help is very much appreciated!

In my database is are two tables: one for inserting contact information and employee status, and the other documenting work history. I created a query that contains only the most recent data entered and from that query I created a cross-tab query that reads the data in the query and returns the list of all the names as the row headers, the status as the column header, and the totalCount as the value. Whenever the cross-tab is run, it works as it's suppose to by supplying all the names in the Y-axis, all the status types in the X-axis, and the count of each type in the columns. When a user modifies the status for the employee the query is updated, sometimes the status may change or a new status type is added to. For example the query may return:





Then if a new name is added to the table the cross-tab query is updated:





Now that all works. The problem is that when it comes time to making a report I'm lost on about how to make the report dynamic in the sense of having it display the data in Ex. 1 but when new information is added having it updated to display the data in Ex. 2 automatically. Eventually I would like to add subtotals in the report to show the current number of status_types there are for example:





I assume I will have to do some VBA and perhaps SQL magic but I don't know about how to do that. Can anyone please provide me wuth some code snippets (if any) or direct me in a new direction from how I am approaching this?
Mar 26 '07 #2
nico5038
3,080 Expert 2GB
When you have a "fixed" maximum number of columns, then adding a table with the max number of columnheader values can be a solution. Connecting this table with the original query in a Left or Right JOIN will force all values.

The alternative is to fill the report dynamically from code.
Making the columnheader and detaildata flexible is possible, but needs some VBA code in the OpenReport event.

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.

This sample 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:

Private Sub Report_Open(Cancel As Integer)
Dim intI As Integer

Dim rs As Recordset

Set rs = CurrentDb.OpenRecordset(Me.RecordSource)

'Place headers
For intI = 3 To rs.Fields.Count - 1
Me("lblCol" & intI - 1).Caption = rs.Fields(intI).Name
Next intI

'Place correct controlsource
For intI = 3 To rs.Fields.Count - 1
Me("Col" & intI - 1).ControlSource = rs.Fields(intI).Name
Next intI

'Place Total field
Me.ColTotal.ControlSource = "=SUM([" & rs.Fields(2).Name & "])"

End Sub

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 it could differ for you.

Nic;o)
Mar 27 '07 #3
I was able to get the column headings working great--thank you so much! However, I'm not able to get the fields filled in under those headings.
The code:

'Place correct controlsource
For intI = 3 To rs.Fields.Count - 1
Me("Col" & intI - 1).ControlSource = rs.Fields(intI).Name
Next intI

runs without error but when I open the report the records do not show. Here's my code:

Dim intI As Integer
Dim qdf As QueryDef
Dim frm As Form

Set dbsReport = CurrentDb
Set frm = Forms!RetrieveForm
Set qdf = dbsReport.QueryDefs("prototypeInternReportQuery_Cr osstab")
qdf.Parameters("Forms!RetrieveForm!Text49") = frm!Text49
qdf.Parameters("Forms!RetrieveForm!Text51") = frm!Text51

Set rstReport = qdf.OpenRecordset()

ColumnCount = rstReport.Fields.Count
'Set rs = CurrentDb.OpenRecordset("prototypeInternReportQuer y_Crosstab")

Debug.Print "Run times: " & ColumnCount

'Place headers
'Debug.Print "Outside loop"
For intI = 10 To ColumnCount - 1
Me("lblCol" & intI).Caption = rstReport.Fields(intI).Name
Next intI

'Place correct controlsource
For intI = 10 To colunmCount
Me("Col" & intI).ControlSource = rstReport.Fields(intI).Name
Debug.Print rstReport.Fields(intI).Name
Next intI

The colunm count was different from your code but your logic worked out just fine, but it's the control source where I'm having difficulty. Since it is a crosstab query is there a different function I have to call?

When you have a "fixed" maximum number of columns, then adding a table with the max number of columnheader values can be a solution. Connecting this table with the original query in a Left or Right JOIN will force all values.

The alternative is to fill the report dynamically from code.
Making the columnheader and detaildata flexible is possible, but needs some VBA code in the OpenReport event.

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.

This sample 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:

Private Sub Report_Open(Cancel As Integer)
Dim intI As Integer

Dim rs As Recordset

Set rs = CurrentDb.OpenRecordset(Me.RecordSource)

'Place headers
For intI = 3 To rs.Fields.Count - 1
Me("lblCol" & intI - 1).Caption = rs.Fields(intI).Name
Next intI

'Place correct controlsource
For intI = 3 To rs.Fields.Count - 1
Me("Col" & intI - 1).ControlSource = rs.Fields(intI).Name
Next intI

'Place Total field
Me.ColTotal.ControlSource = "=SUM([" & rs.Fields(2).Name & "])"

End Sub

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 it could differ for you.

Nic;o)
Mar 29 '07 #4
nico5038
3,080 Expert 2GB
Guess the intI subscript needs some corrective work. Best to place a break (click in the left ruler for a dot to appear) in the code and inspect the value of the fields by using in the immediate window:
?rstReport.Fields(1).Name
and press enter. This will reveal the value for field(1) and check or the value corresponds with the label where Me("lblCol" & intI).Caption is pointing to.

Keep in mind that the rowheaderfield(s) needs to be skipped.

Nic;o)
Mar 29 '07 #5
Thanks! I got it!

Guess the intI subscript needs some corrective work. Best to place a break (click in the left ruler for a dot to appear) in the code and inspect the value of the fields by using in the immediate window:
?rstReport.Fields(1).Name
and press enter. This will reveal the value for field(1) and check or the value corresponds with the label where Me("lblCol" & intI).Caption is pointing to.

Keep in mind that the rowheaderfield(s) needs to be skipped.

Nic;o)
Apr 2 '07 #6

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

Similar topics

3
by: Nicola | last post by:
Hi Everyone, I am new to programming and would like to know how to open an access Report from within vb 6. I am trying to write a program to organise cross stitch threads. I have found out how...
0
by: alexz | last post by:
Generating a report Alexander | Posted 11:05am 31. March 2004 Server Time | 3 Tables 1) Titles - The course titles 2) Courses - The schedules Courses 3) Students - Coueses a Student is...
0
by: Raghavendra | last post by:
hi, we r using forms authetication. problem :- i am using the below code to generate excel report but since we r using forms authetication.. after generating excel report the browser directs...
2
by: Vikram | last post by:
i want simple report functionality for which i do not want to use any reporting tool like crystal etc. Is there any class or code available which can be used for generating reports using asp.net...
2
by: Girish Sahani | last post by:
hello ppl, Consider a list like . Here 'a','b','c' are objects and 1,3,4,2 are their instance ids and they are unique e.g. a.1 and b.1 cannot exist together. From this list i want to generate...
3
by: billa856 | last post by:
Hi, >I have project in MS access. >In that project I am generating some reports for my company. >Now In my form I have one combobox(PalletNo_combo) >when I select an item from combobox and then...
0
by: Aswanth | last post by:
I'm Generating Reports in SSRS-2005.. Previously I got the Data from One Database & Generated Reports.. Now I used to get the Data from Two Different Databases(ie Database-1 & Database-2) & to...
0
by: Aswanth | last post by:
I'm Working with Asp.Net with C#.. & I'm Generating Reports in SSRS-2005.. Till Now I'm Generating Reports in SSRS-2005 with Stored Procedure.. in Which I'm Generating Reports for One...
1
by: VictorLeo | last post by:
I have an application that this throws with VS 2008 and LINQ everything works well, the problem is when I try to create an installer for this project. Adding a project to install add the main...
2
by: veer | last post by:
hi i made program in which i am generating the report of a ms-table database it works fine only on my computer and generatin the reports but when i run this exe on any computer the whole programe...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.