473,399 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Multiple Sort in a Continuous Form - Similiar to AutoFilter

Good Evening all, I would greatly appreciate any assistance on this
Access 2003 quandary I'm in. And I do apologize if this has been
answered somewhere else, I didn't see one that addressed my problem
though. I'm looking to be able to sort multiple fields from a form
whose record source is a query of fields from a single table.

Background:
The default view is "Continuous Forms." and in the Form Header
section of the form's design, I have 4 'combo boxes' that are
made to look like drop-down lists. They go left to right in this order:
IPT, Tier5, Risk, and Status. The Row Source Type is 'Table/Query'
and the Row Source for the first looks like: "SELECT IPT.ipt FROM
IPT ORDER BY IPT.ipt;"

The [Event Procedure] for 'On Change' has this Visual basic code
for the 4 combo boxes:
___
Private Sub Combo49_Change()
DoCmd.ApplyFilter , "[IPT] = '" & Me.Combo49 & "'"
End Sub
___
Private Sub Combo83_Change()
DoCmd.ApplyFilter , "[Tier5] = '" & Me.Combo83 & "'"
End Sub
___
Private Sub Combo71_Change()
DoCmd.ApplyFilter , "[Risk] = '" & Me.Combo71 & "'"
End Sub
___
Private Sub Combo72_Change()
DoCmd.ApplyFilter , "[OpenClosed] = '" & Me.Combo72 & "'"
End Sub
___

Issue:
The filters work fine and instantly filter hundreds of fields, but I
can only sort one at a time, rather than have it lock in the filter of
'IPT', and then let me choose from the available fields in
'Tier5' and so on.
In a nutshell, I'd like it to do what Autofilter does for an Excel
spreadsheet, if this is possible.

Thanks in advance for your time.
-RQ

Nov 13 '05 #1
3 10327
You want to filter by the value of the combo, and sort by that field as
well?

My preferred approach would be to use the AfterUpdate event of the combo to
set the Filter and OrderBy properties of the form, like this:
Private Sub Combo49_AfterUpdate()
If Me.Dirty Then Me.Dirty = False 'Save first
Me.Filter = "[IPT] = '" & Me.Combo49 & "'"
Me.OrderBy = "[IPT]"
Me.FilterOn = True
Me.OrderByOn = True
End Sub
It might be even more efficient to change the RecordSource of the form to a
query string, but the users can't just remove the filter as easily that way.

I don't think you were asking how to assign the secondary and tertiary
fields to the sorting order (so it sorts by IPT first, and then within that
by Tier5, and then within that by Risk), but the code would be:
Me.OrderBy = "IPT, Tier5, Risk"
--
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.

"rquinnan" <rq******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Good Evening all, I would greatly appreciate any assistance on this
Access 2003 quandary I'm in. And I do apologize if this has been
answered somewhere else, I didn't see one that addressed my problem
though. I'm looking to be able to sort multiple fields from a form
whose record source is a query of fields from a single table.

Background:
The default view is "Continuous Forms." and in the Form Header
section of the form's design, I have 4 'combo boxes' that are
made to look like drop-down lists. They go left to right in this order:
IPT, Tier5, Risk, and Status. The Row Source Type is 'Table/Query'
and the Row Source for the first looks like: "SELECT IPT.ipt FROM
IPT ORDER BY IPT.ipt;"

The [Event Procedure] for 'On Change' has this Visual basic code
for the 4 combo boxes:
___
Private Sub Combo49_Change()
DoCmd.ApplyFilter , "[IPT] = '" & Me.Combo49 & "'"
End Sub
___
Private Sub Combo83_Change()
DoCmd.ApplyFilter , "[Tier5] = '" & Me.Combo83 & "'"
End Sub
___
Private Sub Combo71_Change()
DoCmd.ApplyFilter , "[Risk] = '" & Me.Combo71 & "'"
End Sub
___
Private Sub Combo72_Change()
DoCmd.ApplyFilter , "[OpenClosed] = '" & Me.Combo72 & "'"
End Sub
___

Issue:
The filters work fine and instantly filter hundreds of fields, but I
can only sort one at a time, rather than have it lock in the filter of
'IPT', and then let me choose from the available fields in
'Tier5' and so on.
In a nutshell, I'd like it to do what Autofilter does for an Excel
spreadsheet, if this is possible.

Thanks in advance for your time.
-RQ

Nov 13 '05 #2
Allen, Thanks for getting back so quickly. I tried your code, and it
still has the same issue. I actually think I might not be explaining
myself clearly. I'm not as concerned as to how the fields will be
laid out after the initial filter. But I'm more interested in the
drop down narrowing the next sort to only those matched. For example,
if my data in the form looks like this:

IPT Tier5
Team A Browne
Team A Larry
Team A Browne
Team X Johnson
Team X Browne
Team X Smith

When I click the drop-down filter for 'IPT' and select 'Team A"
then the result is:

IPT Tier5
Team A Browne
Team A Larry
Team A Browne

But when I click the next combo box drop down for 'Tier5' and
select 'Browne' the result is this:

IPT Tier5
Team A Browne
Team A Browne
Team X Browne

It has forgotten the previous filter of 'Team A' and simply listed
ALL occurrences of 'Browne'
I'd like the result to be a filter by 'Team A' and 'Browne'
Example:

IPT Tier5
Team A Browne
Team A Browne

Again, just like Excel's AutoFilter that "holds" the filter (and
switches the drop-down arrow color to blue) and allows you to filter
the results of the previous filter. Can it be done in MS Access?

Thanks again for your time!!

Nov 13 '05 #3
Okay, so you want to create a string that adds in the value of all the
non-blank combos.

This example is set up so that it creates a filter from any of the combos
that have a value. It tacks an " AND " on the end, so it's easy to add as
many as you wish. Then at the end it chops off the trailing " AND ", and
applies the filter.

You can code it in one of the combos, and then call the code from the other
combos to the filter gets applied as soon as any combo is updated.

Private Sub Combo49_AfterUpdate()
Dim strWhere As String
Dim lngLen As Long

If Me.Dirty Then Me.Dirty = False 'Save first

If Not IsNull(Me.Combo49) Then
strWhere = strWhere & "([IPT] = '" & Me.Combo49 & "') AND "
End If

If Not IsNull(Me.Combo83) Then
strWhere = strWhere & "([Tier5] = '" & Me.Combo83 & "') AND "
End If

'etc for other combos.

lngLen = Len(strWhere) - 5 'Without trailing " AND ".
If lenLen > 0 Then
strWhere = Left$(strWhere, lngLen)
Me.Filter = strWhere
Me.FilterOn True
Else
MsgBox "No criteria."
End If
End Sub

Private Sub Combo83_AfterUpdate()
Call Combo49_AfterUpdate
End Sub
Note that this example assumes:
- All these combos are unbound (for filtering only), and
- IPT, Tier5, etc are all Text type fields. Remove the extra quotes for
number fields.

--
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.

"rquinnan" <rq******@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Allen, Thanks for getting back so quickly. I tried your code, and it
still has the same issue. I actually think I might not be explaining
myself clearly. I'm not as concerned as to how the fields will be
laid out after the initial filter. But I'm more interested in the
drop down narrowing the next sort to only those matched. For example,
if my data in the form looks like this:

IPT Tier5
Team A Browne
Team A Larry
Team A Browne
Team X Johnson
Team X Browne
Team X Smith

When I click the drop-down filter for 'IPT' and select 'Team A"
then the result is:

IPT Tier5
Team A Browne
Team A Larry
Team A Browne

But when I click the next combo box drop down for 'Tier5' and
select 'Browne' the result is this:

IPT Tier5
Team A Browne
Team A Browne
Team X Browne

It has forgotten the previous filter of 'Team A' and simply listed
ALL occurrences of 'Browne'
I'd like the result to be a filter by 'Team A' and 'Browne'
Example:

IPT Tier5
Team A Browne
Team A Browne

Again, just like Excel's AutoFilter that "holds" the filter (and
switches the drop-down arrow color to blue) and allows you to filter
the results of the previous filter. Can it be done in MS Access?

Thanks again for your time!!

Nov 13 '05 #4

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

Similar topics

4
by: Kathy | last post by:
What is the standard technique for handling the fields in the following scenario on a continuous form? Multiple Divisions. Each Division has multiple Buildings. Each Building has a Supervisor. ...
3
by: Leo | last post by:
Hi everybody, Is there a way to fill a continuous form with an ADO recordset? Normally when I populate the form with the recordset only the first record is shown. I want to fill all records....
10
by: DFS | last post by:
I'm sure this has been discussed before, but I'm too tired to hunt for it. I have a survey table containing questions with different answer scales. Some are 1 to 5, others are A,B,C, etc. I show...
20
by: Robert | last post by:
Need some help to stop me going around in circles on this one.... Have a nested subform (subform2) which simulates a continuous form for the record on the parent subform. Subform2 has rows of...
2
by: bobh | last post by:
Hi All, In Access97 I have a form setup as a continuous form several of the bound controls have calculations that are done in the 'after update' event via VBA code and all works fine. My...
3
by: S P Arif Sahari Wibowo | last post by:
Hi! I would like to make an editable continous form, where most fields will be from table A and editable, except 1-3 fields are a glimpse into table B and uneditable. Table A relate to table B...
2
by: Steve | last post by:
I have a continuous form showing Product Code and Product Name. Product Code is five digits and is sequential. I have a textbox in the form header. What is the code to scroll the continuous form so...
1
by: MikiEns | last post by:
Hi all, Please excuse me if this is incorrect I am new to MS access and this Forum and appreciate any advice on posting. I would Like the Tab key on the key board to take the cursor down...
1
realayumi
by: realayumi | last post by:
ACCESS 2003 WIN XP Hi, i'm new in access, just a view days, this is my first post. Sorry for my bad English. I have 3 tables. tbl_product
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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...
0
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...
0
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
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
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,...

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.