473,809 Members | 2,776 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 2638
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(Can cel As Integer)
Dim intI As Integer

Dim rs As Recordset

Set rs = CurrentDb.OpenR ecordset(Me.Rec ordSource)

'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).ControlSourc e = rs.Fields(intI) .Name
Next intI

'Place Total field
Me.ColTotal.Con trolSource = "=SUM([" & rs.Fields(2).Na me & "])"

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).ControlSourc e = 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!RetrieveF orm
Set qdf = dbsReport.Query Defs("prototype InternReportQue ry_Crosstab")
qdf.Parameters( "Forms!Retrieve Form!Text49") = frm!Text49
qdf.Parameters( "Forms!Retrieve Form!Text51") = frm!Text51

Set rstReport = qdf.OpenRecords et()

ColumnCount = rstReport.Field s.Count
'Set rs = CurrentDb.OpenR ecordset("proto typeInternRepor tQuery_Crosstab ")

Debug.Print "Run times: " & ColumnCount

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

'Place correct controlsource
For intI = 10 To colunmCount
Me("Col" & intI).ControlSo urce = rstReport.Field s(intI).Name
Debug.Print rstReport.Field s(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(Can cel As Integer)
Dim intI As Integer

Dim rs As Recordset

Set rs = CurrentDb.OpenR ecordset(Me.Rec ordSource)

'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).ControlSourc e = rs.Fields(intI) .Name
Next intI

'Place Total field
Me.ColTotal.Con trolSource = "=SUM([" & rs.Fields(2).Na me & "])"

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.Fiel ds(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.Fiel ds(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
23881
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 to use a database table but all I want to do now is to click a command button to display this access report. Any suggestions please ?????
0
1232
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 taking and the student attendance Relationships are Titles.ID on Courses.TitleID
0
1448
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 to login.apsx which is specified in web.config file. this code is in one file.aspx
2
1428
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 only
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 multiple lists such that each list must have one and only one instance of every object. Thus, for the above list, my output should be: ,] Another example: Let l = . Then
3
4278
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 click on search button then it will generate Report on search criteria. >Now in that report I have 15-20 fields like PalletNo,OrderDate,CustmerCode,ShippingLocation,Cartons,PartialCartons,ShippedDate,TotalQuantity,ShippedQuantity etc >Now when...
0
1863
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 generate the Reports.. I'm having one Stored Procedure(Get_Data) which will combine Two databases & get the data from them.. It is working fine for Me..(I tested in Sql Server Management Studio).. But it is Not working fine in my Visual Studio.. ...
0
1884
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 Particular User Details(ie I wrote Stored Procedure for Getting One Users Details).. Now I Want to Generate the Reports for Different Users DYNAMICALLY (Here, I wrote another Stored Procedure which contains UsersID's as Input...
1
1198
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 results of the project as it is commonly I generate the installer and it gives me an error in the generation but I said that wrong or anything that file was also concerned with adding all the results osea the source for the project xml and nothing...
2
1474
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 works fine except generating the report when i click on button which generates the report it shows the error "COULD NOT LOD FILE OR ASSEMBLY 'MICROSOFT.REPORTVIEWER.WINFORMS,VERSION=9.0.0.0, CULTURE=NEUTRAL, PUBLICKEYTOKEN= b03f5f11d50a3a , OR ONE...
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10640
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10120
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.