473,503 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generating a report over a cross-tab query

24 New Member
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 2620
Cyrax1033
24 New Member
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 Recognized Expert Specialist
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
Cyrax1033
24 New Member
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 Recognized Expert Specialist
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
Cyrax1033
24 New Member
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
23846
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
1220
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
1424
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
1413
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
310
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
4251
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
1831
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
1873
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
1178
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
1457
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
7194
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
7267
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,...
1
6976
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
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5566
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,...
1
4993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.