473,545 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Crosstab query reports (unknown fields in reports) What about sorting?

Hi,

I've been trying to work out how to create a report based on crosstab
query for which the number of fields is variable. For example in a
situation where you show customer billing by year in the following
format:

Customer 2000 2001 2002
Bill 103 10 205
Frank 12 50
George 200 50

where you might need a new column to appear where 2003 or 1999
billings are in the data.

The good news is that I've come across some really clever code in the
"bible" (Access 2000 Developers Handbook) which can do this. No doubt
this code is readily available in other places too.

Basically the code is placed in the report's open event and it
populates the controls in the report so that they link up with the
field in the cross tab query. (Let me know if I need to expand on
this).

My problem now though is that I want to sort this data by the billings
(eg 2002, then 2001 then 2000).

My thinking here that there must be a relatively easy way to include
something in the code which populated the Grouping and Sorting
property of the form.

Anyone know what the code is? or have a better idea?

Mat
Nov 13 '05 #1
3 5214
You can assign the ControlSource of the GroupLevel in Report_Open.

Example at:
http://allenbrowne.com/ser-33.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mat N" <Ma******@hotma il.com> wrote in message
news:d2******** *************** **@posting.goog le.com...

I've been trying to work out how to create a report based on crosstab
query for which the number of fields is variable. For example in a
situation where you show customer billing by year in the following
format:

Customer 2000 2001 2002
Bill 103 10 205
Frank 12 50
George 200 50

where you might need a new column to appear where 2003 or 1999
billings are in the data.

The good news is that I've come across some really clever code in the
"bible" (Access 2000 Developers Handbook) which can do this. No doubt
this code is readily available in other places too.

Basically the code is placed in the report's open event and it
populates the controls in the report so that they link up with the
field in the cross tab query. (Let me know if I need to expand on
this).

My problem now though is that I want to sort this data by the billings
(eg 2002, then 2001 then 2000).

My thinking here that there must be a relatively easy way to include
something in the code which populated the Grouping and Sorting
property of the form.

Anyone know what the code is? or have a better idea?

Mat

Nov 13 '05 #2
Allen,

Just what I needed. Thanks.

Just to complete the thread here's the bit of code the solved my
problem:

'Fill in information for the necessary controls.
For i = 1 To intColCount
strName = rst.Fields(i - 1).Name
Me.Controls("lb lHeader" & i).Caption = strName
Me.Controls("tx tData" & i).ControlSourc e = strName
Me.Controls("tx tSum" & i).ControlSourc e = _
"=Sum([" & strName & "])"
If i > 1 Then
Me.GroupLevel(i - 1).ControlSourc e = strName
Me.GroupLevel(i - 1).SortOrder = True
End If
Next i

Notice that I included "SortOrder" which when true means descending
and also the if statement avoids sorting by the first field.

Mat N

"Allen Browne" <Al*********@Se eSig.Invalid> wrote in message news:<40******* *************** *@per-qv1-newsreader-01.iinet.net.au >...
You can assign the ControlSource of the GroupLevel in Report_Open.

Example at:
http://allenbrowne.com/ser-33.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mat N" <Ma******@hotma il.com> wrote in message
news:d2******** *************** **@posting.goog le.com...

I've been trying to work out how to create a report based on crosstab
query for which the number of fields is variable. For example in a
situation where you show customer billing by year in the following
format:

Customer 2000 2001 2002
Bill 103 10 205
Frank 12 50
George 200 50

where you might need a new column to appear where 2003 or 1999
billings are in the data.

The good news is that I've come across some really clever code in the
"bible" (Access 2000 Developers Handbook) which can do this. No doubt
this code is readily available in other places too.

Basically the code is placed in the report's open event and it
populates the controls in the report so that they link up with the
field in the cross tab query. (Let me know if I need to expand on
this).

My problem now though is that I want to sort this data by the billings
(eg 2002, then 2001 then 2000).

My thinking here that there must be a relatively easy way to include
something in the code which populated the Grouping and Sorting
property of the form.

Anyone know what the code is? or have a better idea?

Mat

Nov 13 '05 #3
Actually the code I used didn't appear to work properly but I've
worked out the problem.

Basically the code would work except that Grouplevels can only be
created in design view.

The work around is to create dummy grouplevel in the design view which
you edit later using the same code. I designed my report so that it
can show up 7 columns of numbers and so I've simply created the
Grouplevel using the following expressions:

=2
=3
....
=6
=7

It shouldn't matter what you use so long as it is an expression and
you have enough to cover the maximum number of group levels you might
need.

Works a treat now.

Mat N

Ma******@hotmai l.com (Mat N) wrote in message news:<d2******* *************** ****@posting.go ogle.com>...
Allen,

Just what I needed. Thanks.

Just to complete the thread here's the bit of code the solved my
problem:

'Fill in information for the necessary controls.
For i = 1 To intColCount
strName = rst.Fields(i - 1).Name
Me.Controls("lb lHeader" & i).Caption = strName
Me.Controls("tx tData" & i).ControlSourc e = strName
Me.Controls("tx tSum" & i).ControlSourc e = _
"=Sum([" & strName & "])"
If i > 1 Then
Me.GroupLevel(i - 1).ControlSourc e = strName
Me.GroupLevel(i - 1).SortOrder = True
End If
Next i

Notice that I included "SortOrder" which when true means descending
and also the if statement avoids sorting by the first field.

Mat N

"Allen Browne" <Al*********@Se eSig.Invalid> wrote in message news:<40******* *************** *@per-qv1-newsreader-01.iinet.net.au >...
You can assign the ControlSource of the GroupLevel in Report_Open.

Example at:
http://allenbrowne.com/ser-33.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mat N" <Ma******@hotma il.com> wrote in message
news:d2******** *************** **@posting.goog le.com...

I've been trying to work out how to create a report based on crosstab
query for which the number of fields is variable. For example in a
situation where you show customer billing by year in the following
format:

Customer 2000 2001 2002
Bill 103 10 205
Frank 12 50
George 200 50

where you might need a new column to appear where 2003 or 1999
billings are in the data.

The good news is that I've come across some really clever code in the
"bible" (Access 2000 Developers Handbook) which can do this. No doubt
this code is readily available in other places too.

Basically the code is placed in the report's open event and it
populates the controls in the report so that they link up with the
field in the cross tab query. (Let me know if I need to expand on
this).

My problem now though is that I want to sort this data by the billings
(eg 2002, then 2001 then 2000).

My thinking here that there must be a relatively easy way to include
something in the code which populated the Grouping and Sorting
property of the form.

Anyone know what the code is? or have a better idea?

Mat

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
8660
by: Dave | last post by:
I came across an article in SQL Mag about Crosstab Queries. It works great in Query Analyzer, but I'm stuck on how to use it in an Access ADP. I need to use it as a Recordsource in a form and report. Can someone tell me how to use it, and please try to be as descriptive as possible. I'm new to Stored Procedures. Thanks ...
8
7555
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...
1
17646
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
10
1648
by: pw | last post by:
Hi, Is that possible if the crosstab query is dynamic? Doesn't seem so as I have to specify the control source for the text boxes and the number of columns may change, along with their field names. Just thought I'd take a shot in the dark. -pw
1
3323
by: Richard Hollenbeck | last post by:
Hello Newsgroup. You have all been very helpful in the past and I thank you. I try to ask relevant questions so that they don't just benefit me, but also benefit the group. I'm currently overwhelmed by useless examples across the web on how to make "dynamic crosstab reports" without myself having a basic understanding about how to retrieve...
2
6517
by: luca varani | last post by:
I would like to sort the results of a crosstab query by the aggregate function it automatically generates (total of the values in each column of the crosstab). If I simply put "ascending" in the sort field of the design view I get the following error message: "cannot have aggregate function in order by clause". I had no success trying to...
14
3472
by: Tina | last post by:
My employer tracks productivity/performance of clinicians (how much they bill) each week, its averages for the month, and the 6 months. These averages are compared to their expected productivity. However, the expectation changes - it may be 60% for a while, then change to 50%. Initially, I was averaging the expectation, along with the...
6
4446
by: tizmagik | last post by:
I am having a lot of difficulty generating a CrossTab Query based report. I have looked online for several tutorials and whatnot but I have not been able to really find what I'm looking for, nor have I been able to adapt other people's solutions/tips to fit what I need. If anyone could please help me with the following it would be really...
0
2306
by: Peter Herath | last post by:
I want to create a custormizable report . 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...
0
7470
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...
0
7659
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. ...
1
7428
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7760
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...
0
5975
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...
1
5334
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4949
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...
0
3455
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
709
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...

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.