473,726 Members | 2,262 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help on Sorting a Report using VBA

ARC
I have a ranking report where I want to sort it different ways depending on
the option the user picks. On the On_Open event, I've tried everything I can
think of and keep getting error 3071 "This expression is typed incorrectly
or is too complex..."

Here's the 2 things I've tried, both return the error 3071. If I comment out
the code, the report opens normally. The fields SumOfInvTot, Margin,
MarginPCT, and Comp all exist both in the report and in the query.
OrderBy:
----------
Select Case Forms!fReports. Form!lstReports (this is the reportID in a table
of reports)
Case 56 'sales ranking by total invoices $
Me.OrderBy = "SumOfInvTo t DESC, Margin DESC, MarginPct DESC, Comp"
Case 110 'sales ranking by profit $
Me.OrderBy = "Margin DESC, MarginPct DESC, SumOfInvTot DESC, Comp"
end select

(Note: OrderByOnLoad is set to true)

Group Level approach:
------------------------
I added 4 groups to the report, and set all 4 to "without a header section"
and "without a footer section", so really there are 4 sort levels.

Select Case Forms!fReports. Form!lstReports
Case 56 'sales ranking by total invoices $
Me.GroupLevel(0 ).ControlSource = "SumOfInvTo t"
Me.GroupLevel(0 ).SortOrder = True 'Set to Descending
Me.GroupLevel(1 ).ControlSource = "Margin"
Me.GroupLevel(1 ).SortOrder = True 'Set to Decending
Me.GroupLevel(2 ).ControlSource = "MarginPct"
Me.GroupLevel(2 ).SortOrder = True 'Set to Decending
Me.GroupLevel(3 ).ControlSource = "Comp"
Me.GroupLevel(3 ).SortOrder = False 'Set to Acending
Case 110 'sales ranking by profit $
Me.GroupLevel(0 ).ControlSource = "Margin"
Me.GroupLevel(0 ).SortOrder = True 'Set to Decending
Me.GroupLevel(1 ).ControlSource = "MarginPct"
Me.GroupLevel(1 ).SortOrder = True 'Set to Decending
Me.GroupLevel(2 ).ControlSource = "SumOfInvTo t"
Me.GroupLevel(2 ).SortOrder = True 'Set to Decending
Me.GroupLevel(3 ).ControlSource = "Comp"
Me.GroupLevel(3 ).SortOrder = False 'Set to Accending
end select
Any ideas? This one's driving me batty....

Oct 28 '08 #1
2 5450
ARC wrote:
I have a ranking report where I want to sort it different ways depending
on the option the user picks. On the On_Open event, I've tried
everything I can think of and keep getting error 3071 "This expression
is typed incorrectly or is too complex..."

Here's the 2 things I've tried, both return the error 3071. If I comment
out the code, the report opens normally. The fields SumOfInvTot, Margin,
MarginPCT, and Comp all exist both in the report and in the query.
OrderBy:
----------
Select Case Forms!fReports. Form!lstReports (this is the reportID in a
table of reports)
Case 56 'sales ranking by total invoices $
Me.OrderBy = "SumOfInvTo t DESC, Margin DESC, MarginPct DESC, Comp"
Case 110 'sales ranking by profit $
Me.OrderBy = "Margin DESC, MarginPct DESC, SumOfInvTot DESC, Comp"
end select

(Note: OrderByOnLoad is set to true)
That must be a 2007 thang. Still, I'd put an
Me.OrderByOn = True
after setting the OrderBy value.
>
Group Level approach:
------------------------
I added 4 groups to the report, and set all 4 to "without a header
section" and "without a footer section", so really there are 4 sort levels.

Select Case Forms!fReports. Form!lstReports
Case 56 'sales ranking by total invoices $
Me.GroupLevel(0 ).ControlSource = "SumOfInvTo t"
Me.GroupLevel(0 ).SortOrder = True 'Set to Descending
Me.GroupLevel(1 ).ControlSource = "Margin"
Me.GroupLevel(1 ).SortOrder = True 'Set to Decending
Me.GroupLevel(2 ).ControlSource = "MarginPct"
Me.GroupLevel(2 ).SortOrder = True 'Set to Decending
Me.GroupLevel(3 ).ControlSource = "Comp"
Me.GroupLevel(3 ).SortOrder = False 'Set to Acending
Case 110 'sales ranking by profit $
Me.GroupLevel(0 ).ControlSource = "Margin"
Me.GroupLevel(0 ).SortOrder = True 'Set to Decending
Me.GroupLevel(1 ).ControlSource = "MarginPct"
Me.GroupLevel(1 ).SortOrder = True 'Set to Decending
Me.GroupLevel(2 ).ControlSource = "SumOfInvTo t"
Me.GroupLevel(2 ).SortOrder = True 'Set to Decending
Me.GroupLevel(3 ).ControlSource = "Comp"
Me.GroupLevel(3 ).SortOrder = False 'Set to Accending
end select
Any ideas? This one's driving me batty....
If you step thru the code does it break on the
Me.GroupLevel(0 ).ControlSource =...
or the
Me.GroupLevel(0 ).SortOrder = ...
or some other line? Maybe put the word
STOP
just before the
Select Case Forms!fReports. Form!lstReports
line. It might help if we knew where it was blowing up.

Oct 28 '08 #2
ARC
Ok, now I feel silly... I was only taking a quick look at the query results,
and there were many records. Well, if I scrolled to the bottom, I had a
#Error in the Margin % field, so the one bad query result was causing the
error 3071...
"ARC" <PC*****@PCESof t.invalidwrote in message
news:1g******** ********@nlpi07 0.nbdc.sbc.com. ..
>I have a ranking report where I want to sort it different ways depending on
the option the user picks. On the On_Open event, I've tried everything I
can think of and keep getting error 3071 "This expression is typed
incorrectly or is too complex..."

Here's the 2 things I've tried, both return the error 3071. If I comment
out the code, the report opens normally. The fields SumOfInvTot, Margin,
MarginPCT, and Comp all exist both in the report and in the query.
OrderBy:
----------
Select Case Forms!fReports. Form!lstReports (this is the reportID in a
table of reports)
Case 56 'sales ranking by total invoices $
Me.OrderBy = "SumOfInvTo t DESC, Margin DESC, MarginPct DESC, Comp"
Case 110 'sales ranking by profit $
Me.OrderBy = "Margin DESC, MarginPct DESC, SumOfInvTot DESC, Comp"
end select

(Note: OrderByOnLoad is set to true)

Group Level approach:
------------------------
I added 4 groups to the report, and set all 4 to "without a header
section" and "without a footer section", so really there are 4 sort
levels.

Select Case Forms!fReports. Form!lstReports
Case 56 'sales ranking by total invoices $
Me.GroupLevel(0 ).ControlSource = "SumOfInvTo t"
Me.GroupLevel(0 ).SortOrder = True 'Set to Descending
Me.GroupLevel(1 ).ControlSource = "Margin"
Me.GroupLevel(1 ).SortOrder = True 'Set to Decending
Me.GroupLevel(2 ).ControlSource = "MarginPct"
Me.GroupLevel(2 ).SortOrder = True 'Set to Decending
Me.GroupLevel(3 ).ControlSource = "Comp"
Me.GroupLevel(3 ).SortOrder = False 'Set to Acending
Case 110 'sales ranking by profit $
Me.GroupLevel(0 ).ControlSource = "Margin"
Me.GroupLevel(0 ).SortOrder = True 'Set to Decending
Me.GroupLevel(1 ).ControlSource = "MarginPct"
Me.GroupLevel(1 ).SortOrder = True 'Set to Decending
Me.GroupLevel(2 ).ControlSource = "SumOfInvTo t"
Me.GroupLevel(2 ).SortOrder = True 'Set to Decending
Me.GroupLevel(3 ).ControlSource = "Comp"
Me.GroupLevel(3 ).SortOrder = False 'Set to Accending
end select
Any ideas? This one's driving me batty....
Oct 28 '08 #3

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

Similar topics

5
2200
by: Steve Patrick | last post by:
Hi All You guys are my last hope, despite spending money on books and hours reading them I still can not achieve the results I need. I have designed a database in Access 2000 based on 1 table, all has gone very well with one exception. The table is based on applications made by potential customers looking to buy franchise rights to particular locations and as part of the process they are asked to list their preferred locations 1 to 4....
8
3536
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At the moment the printed output is usually going to Word. It's turning into an unholy mess, because I'm having to prepare umpteen different Word templates, and the queries that drive them, depending on what events a course has.
3
1460
by: Paul T. Rong | last post by:
Hello there, I am making a report using codes bellow (a part of): ------------------------------- Select Case Forms!!TopBoard Dim strGetSQL As String
1
2473
by: Jon via AccessMonster.com | last post by:
Hi Guys, My "Sorting and Grouping" in my report looks like this: Field/Expression Sort Order sID Ascending ((= Project Name Ascending User *** Ascending ((= rID Ascending
5
2007
by: Mike | last post by:
Hello All, I have a report based upon a query. I have added a control to report footer that calcs the total cost of the inventory: =SUM(). When this total calculation is NOT on the report, the report displays as it should in ascending order by inventory number (inv_num). 1102 1103
3
5417
by: Jimmy | last post by:
Is there a way to sort/group a report based on the second column of a combo box, i.e. the text associated with the primary key number?
3
2397
by: Don | last post by:
I have a "Report" that is created from a "Form". It prints a list of items, you may consider it a shopping list. In any event I use to run this in alphabetical order but have since decided to run it as it comes from the form (random order). My problem is I don't know how to make this happen. The report is sorted in ascending order and I don't know how to change that. I see only two options, ascending or descending. Can you help?...
4
1715
by: access baby | last post by:
i have a huge database based on date and time need to create different report we need to measure our work processes how many order received , order cancelled, completed and count of items completed on or before time. chart or pivot report how do i do that. Please help.
1
1706
by: access baby | last post by:
Hi Below mention is the reply from Salad on my query i created a crosstab query and form not based on any table of qurey but this doesnt work . I somehow have missed something actually i have too many database tables with relationship and need the cycle time of projects. i have a huge database based on date and time need to create
8
2204
by: sara | last post by:
Hi - I have looked at all posts and tried both Allen Browne's Report Sorting at run Time ( Select Case Forms!frmChooseSort!grpSort Case 1 'Name Me.GroupLevel(0).ControlSource = "LastName" Me.GroupLevel(1).ControlSource = "FirstName") ..... And another post that was OrderByOn = True and setting the sort Order.
0
8889
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
8752
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
9401
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...
1
9179
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9116
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...
1
6702
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3228
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 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.