I want to create a dynamic report using a crosstab query...... pls someone look into my attached example database and help me out to do the report generation....
example is like dis...:
there are 4 combo boxes.. when u select an item from each combo box and click the ViewReport Button then those selected item values should go as parameters to the crosstab query in the vba code subroutine and from that the report should be generated.
pls someone out there help me quickly
6 4808 Rabbit 12,516
Recognized Expert Moderator MVP
You'll have to build the SQL string in code and then use that to create a query def that your report is based on. You'll also have to open the report in design view and delete or add fields that the user chose. You can do this using code.
You let them choose fields for the crosstab but you didn't mention anything about letting the user choose whether it will be a row heading, column heading, or value. And if it's a value, what kind of value.
I want to create custormizable report using a crosstab query. For an example, there's a form with four combo boxes and two of them having database tables columns/field names as values in the combo box(one for select row filed and other one for select column filed in the report) when u select items in that combo boxes and press a Button then selected items should go to the crosstab query as parameters and execute the query and then generate the report... here's the code for the crosstab query :-
-----------------------------------------------------
(cboColumns/cboProjectTitle/cboRows/cboIndicator)
These are the combobox parameters pass to the crosstab query after button's being clikced.
------------------------------------------------------------
(sSql = "TRANSFORM Max(IndicatorDa ta.nValue) AS MaxOfnValue " + _
"SELECT " + Trim(Replace(cb oRows, "_", ".")) + " " + _
"FROM [Indicator], IndicatorData, Region, Project " + _
"WHERE Project.tProjTi tle='" + Trim(cboProject Title) + "' AND Project.nProjId =Indicator.nPro jId AND Indicator.tIndi catorName='" + cboIndicator + "' AND Indicator.nIndi catorId=Indicat orData.nIndicat orId AND Region.nRegionI d=IndicatorData .nRegionId " + _
"GROUP BY IndicatorData.n RegionId, " + Trim(Replace(cb oRows, "_", ".")) + " " + _
"PIVOT Format(" + Trim(Replace(cb oColumns, "_", ".")) + ",'yyyy') "
)
pls someone help me out to do this report or tell me is there a way to do this kind of requirement(thi s is a real customer requirement).
Rabbit 12,516
Recognized Expert Moderator MVP
Please do not double post. And do try to respond to the original thread when someone has offered some help.
MODERATOR
I want to create custormizable report using a crosstab query.For an example, there's a form with four combo boxes and two of them having database tables columns/field names as values in the combo box(one for select row filed and other one for select column filed in the report) when u select items in that combo boxes and press a Button then selected items should go to the crosstab query as parameters and execute the query and then what i did was i created a temparary table and insert the values into that temp table using the crosstab query. now what i want is to generate the report using that temp table but every time user selects different row headings and column headings then the report will be changed. so i found a way to create a report using VBA code but at the moment im stuck with dat code.... here's the code for the crosstab query and the temp table and the code for generate the report. :-
-----------------------------------------------------
(cboColumns/cboProjectTitle/cboRows/cboIndicator)
These are the combobox parameters pass to the crosstab query after button's being clikced.
------------------------------------------------------------
Cross Tab Query
(sSql = "TRANSFORM Max(IndicatorDa ta.nValue) AS MaxOfnValue " + _
"SELECT " + Trim(Replace(cb oRows, "_", ".")) + " " + _
"FROM [Indicator], IndicatorData, Region, Project " + _
"WHERE Project.tProjTi tle='" + Trim(cboProject Title) + "' AND Project.nProjId =Indicator.nPro jId AND Indicator.tIndi catorName='" + cboIndicator + "' AND Indicator.nIndi catorId=Indicat orData.nIndicat orId AND Region.nRegionI d=IndicatorData .nRegionId " + _
"GROUP BY IndicatorData.n RegionId, " + Trim(Replace(cb oRows, "_", ".")) + " " + _
"PIVOT Format(" + Trim(Replace(cb oColumns, "_", ".")) + ",'yyyy') "
)
-------------------------------------------------------------------------------------------------------------------
Temp Table
Set dbCurr = DBEngine.Worksp aces(0).Databas es(0)
Dim recCrossTab As Recordset
Dim sString, sFields, sValues As String
sString = "CREATE TABLE X ("
Set recCrossTab = dbCurr.OpenReco rdset(CrossTabS ql)
For i = 0 To recCrossTab.Fie lds.Count - 1
If i = recCrossTab.Fie lds.Count - 1 Then
sString = sString + recCrossTab.Fie lds(i).Name + " Text(50) "
sFields = sFields + recCrossTab.Fie lds(i).Name
Else
sString = sString + recCrossTab.Fie lds(i).Name + " Text(50), "
sFields = sFields + recCrossTab.Fie lds(i).Name + ", "
End If
Next
sString = sString + ") "
Debug.Print sString
DoCmd.RunSQL "Drop Table X"
DoCmd.RunSQL sString
Dim InsertStr As String
InsertStr = "INSERT INTO X (" + sFields + ") values ("
''InsertStr = Replace(InsertS tr,"'",""")
recCrossTab.Mov eFirst
While (recCrossTab.EO F = False And recCrossTab.BOF = False)
For b = 0 To recCrossTab.Fie lds.Count - 1
If b = recCrossTab.Fie lds.Count - 1 Then
sValues = sValues + "'" + CStr(recCrossTa b.Fields(recCro ssTab.Fields(b) .Name)) + "' "
Else
sValues = sValues + "'" + CStr(recCrossTa b.Fields(recCro ssTab.Fields(b) .Name)) + "', "
End If
Next
InsertStr = "INSERT INTO X (" + sFields + ") values (" + sValues + ") "
Debug.Print InsertStr
DoCmd.SetWarnin gs False
DoCmd.RunSQL InsertStr
InsertStr = "INSERT INTO X (" + sFields + ") values ("
sValues = ""
recCrossTab.Mov eNext
Wend
-------------------------------------------------------------------------------------------------------------------
Creating the Report using the VBA Code. This Code is in the Code View of the Report called Custom Report. (Code is taken from:- http://www.microsoft.c om/technet/prodtechnol/office/office2000/proddocs/opg/part3/ch15.mspx)
Private Property Let CustomReport_So urce(RHS As String)
' Create report based on specified data source.
Dim txtNew As Access.TextBox
Dim lblNew As Access.Label
Dim rstSource As ADODB.Recordset
Dim fldData As ADODB.Field
Dim lngTop As Long
Dim lngLeft As Long
lngLeft = 0
lngTop = 0
' Set report's RecordSource property.
Me.Report.Recor dSource = RHS
' Open recordset on specified record source.
Set rstSource = New ADODB.Recordset
rstSource.Open "SELECT * FROM [" & RHS & "];", _
CurrentProject. Connection, adOpenForwardOn ly
' Create corresponding label and text box controls for each field.
For Each fldData In rstSource.Field s
' Create new text box control and size to fit data.
Set txtNew = CreateReportCon trol(Me.Report. Name, acTextBox, _
acDetail, , fldData.Name, lngLeft + 1500, lngTop)
txtNew.SizeToFi t
' Create new label control and size to fit data.
Set lblNew = CreateReportCon trol(Me.Report. Name, acLabel, acDetail, _
txtNew.Name, fldData.Name, lngLeft, lngTop, 1400, txtNew.Height)
lblNew.SizeToFi t
' Increment top value for next control.
lngTop = lngTop + txtNew.Height + 25
Next
CustomReport_So urce_End:
On Error Resume Next
rstSource.Close
Set rstSource = Nothing
Exit Property
End Property
-------------------------------------------------------------------------------------------------------------------
In here we can send the created temp table but I cant access the above property. so i created a sub-routine. and call that in the following Sub Report_Open() method. But It gives an error like this "U must be in design view to create or delete Controls".
Private Sub Report_Open(Can cel As Integer)
CustomReport_So urce("X")
End Sub
pls someone help me out or please tell me is there any other way to do this kind of requirement.
Rabbit 12,516
Recognized Expert Moderator MVP
Just like the error says, you have to open the report in design view to use the code that creates the report. acViewDesign instead of acViewPreview.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Donna Sabol |
last post by:
First, I should start by saying I am creating a database to be used by
some very impatient, non-computer literate people. It needs to be
seameless in it's operation from their point of view. I want them to
do as little as possible when they run their reports.
I have a crosstab query that displays usage of items for each month.
It looks...
|
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 Create a Dynamic Crosstab Report
PRODUCT :Microsoft Access
PROD/VER:1.00 1.10
OPER/SYS:WINDOWS
|
by: Edward |
last post by:
ACCESS 2k
I need to design a report based on a rota system for staff at various
shops. The data is effectively stored in a single table, along the
lines of:
Initials (e.g. BH, FG, RM etc.)
Day (e.g. Monday, Tuesday etc.)
Shop (e.g. Shop1, Shop2 etc.)
StartTime (e.g. 8, 13 etc.)
|
by: No Spam |
last post by:
Dear Access 2000 users,
I have a crosstab query that puts together certain information
perfectly. It has a criteria that is based on a form that limits how
many columns are returned based on the date selected. Here's the
problem:
The report that the crosstab query feeds was initially created to show
all the dates and thus, all 26...
|
by: Richard Hollenbeck |
last post by:
I tried to ask this question before on the 14th of January but I never got a
reply. I'm still struggling with the problem. I'll try to rephrase the
question:
I have a crosstab query with rows of students and columns of activities and
the data are the students' scores in each activity. No problem, almost.
The problem is that there are...
| |
by: deejayquai |
last post by:
Hi
I've created a crosstab query and displayed it as a sub-report in my
main report. This is fine until the data changes and the column names
become incorrect. I know I have to create a 'dynamic crosstab query'
but I don't know how to!! I've read the "How to..." on the Microsoft
site but it mainly gives an example rather than explain the...
|
by: Bryan |
last post by:
I've been looking over this newsgroup, but I can't find an answer to my
problem. I see that a few others have posted this issue over the
years, but none of them got a response. I'll give it another shot.
I have a report that is based on a crosstab query. The crosstab query
is based off of another query, and that has a parameter in the...
|
by: Brad |
last post by:
Thanks for taking the time to read my question.
I have a table of data that has Date, Data and Category. I need to
show, in
a report, each Categories Data by Date. The Date has to be it's own
column
across the top and Category down the left side.
As data is entered, the number of unique dates increases. As a result
the
|
by: AccessIdiot |
last post by:
Hello all,
I have a report that is based on a crosstab query. One of the fields in the crosstab query is based on a query. It is a coded value. When I look at the crosstab query it displays the value. But when I look at the report I get the coded value.
For example, in the table it is;
1 apple
2 orange
3 banana
|
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. ...
|
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...
| |
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...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |