Sorting within a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Is it possible to sort in a form at multiple levels? For example, first you
sort by "town", then within "town" sort by "LastName". An example of how to
do this would be very helpful.

Thanks in advance.
 
Luther said:
Hi,

Is it possible to sort in a form at multiple levels? For example,
first you sort by "town", then within "town" sort by "LastName". An
example of how to do this would be very helpful.

Thanks in advance.

Via the user interface? Click Records -> Filter -> Advanced
Filter/Sort...., drag fields to the field grid of the Filter design
window and set the Sort: line under them to Ascending or Descending,
then click the Apply Filter button (or menu item Filter -> Apply
Filter/Sort.
 
Thank you for answering, Dirk. I already know about the user interface...So
I was hoping to duplicate that process via a command button, keeping in mind
that I need to sort within a sort.

Hope to hear from you soon.
 
Dirk,

I also wanted to add that I want to give the user the flexibility to choose
their own sort order (Ascendign or Descending) and not have it set
automatically for them.
 
Luther said:
Thank you for answering, Dirk. I already know about the user
interface...So I was hoping to duplicate that process via a command
button, keeping in mind that I need to sort within a sort.

Oh, that's actually simpler to tell!

Me.OrderBy = "Town, LastName"
Me.OrderByOn = True

That will sort ascending on Town, then LastName. To sort descending on
LastName, while still sorting ascending on Town, use this:

Me.OrderBy = "Town, LastName DESC"
Me.OrderByOn = True

If the field names contain spaces or other invalid characters, you have
to enclose them in square brackets ([]).
 
Luther said:
Dirk,

I also wanted to add that I want to give the user the flexibility to
choose their own sort order (Ascendign or Descending) and not have it
set automatically for them.

Are you asking for suggestions about a user interface for the purpose?
Once you've determined what the user wants, the code to set the sort
order is very simple, as I showed in my previous message.
 
Ye, indeed.

Dirk Goldgar said:
Are you asking for suggestions about a user interface for the purpose?
Once you've determined what the user wants, the code to set the sort
order is very simple, as I showed in my previous message.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Luther said:
Ye, indeed.

If you only wanted to sort by a one field at a time, I'd recommend the
old, "Click on the column header to sort ascending; click again to sort
descending" approach. But for multiple fields, that really doesn't
work.

You could put combo boxes in the form header section, each combo with
its Row Source Type property set to "Field List". You could also have
an option group, or just a check box, beside each combo box for choosing
ascending vs. descending. In the AfterUpdate event of each combo box or
Ascending/Descending control, you would call a function that evaluates
all of the combos, builds an appropriate Order By string, and applies
it.

That would be the most flexible approach, I think, but it may be more
cumbersome and occupy more form "real estate" than you like. A simpler
alternative would be to pick a relatively small set of sort sequences
that you anticipate users wanting, and put a single combo box on the
form that has these specified as a value list. Then the user could pick
one, and the AfterUpdate event of the combo box would simply apply it.
You could set it up so that the bound-column values of the combo box are
the actual OrderBy strings to be applied, or you could have two columns
in the control -- a user-friendly one to be displayed, and a second one
that is the actual OrderBy string. Either way, you wouldn't have to
analyze the user's choice to build the OrderBy string on the fly.
 
Back
Top