dynamic sorting of a list box?

jatfill

Registered User.
Local time
Today, 15:14
Joined
Jun 4, 2001
Messages
150
This isn't somethingI absolutely have to do, but I thought it would be a nice addition if it's possible...

I have several search results forms that use list boxes to display data. I would really like to be able to turn the column heads into "buttons"... and when a user clicks on the column head, it changes the sort order of the list ascending/descending so they can see the data in whatever sort order they choose
like I said, not a priority, but itwould be a really nice addition if it's possible

Thanks!
 
One solution is to remove the column heads and put actual buttons just above the list box. In the row source of the list box, you can add SQL code to change the listing order when the buttons are clicked.

Keagan Quilty
Kilbride, Newfoundland
 
I was just working on this myself, and I have a solution.
As Keagan suggested I used a command button.
The code for this is:

Name: sorts
Caption: Sort Descending

In the on_click event:

Private Sub sorts_Click()
Dim ctl As Control
Static Toggle
If sorts.Caption = "Sort Descending" Then
Toggle = " DESC;"
sorts.Caption = "Sort Ascending"
Me.refresh
Else
Toggle = ";"
sorts.Caption = "Sort Descending"
Me.refresh
End If
Const Row_Source = "SELECT YourQuery.yourfield FROM YourQuery ORDER BY Yourquery.yourfield"
Set ctl = List1
ctl.RowSource = Row_Source & Toggle
Me.Requery
ctl.Requery
End Sub

***Notes***
You can just cut and paste the RowSource of your list box into this code, but make sure you remove the last ;
Also make sure that Sort :Ascending in the row source.

Well HTH

Angelo
 
Try looking at the colored buttons example on
http://www.peterssoftware.com

I have been thinking that instead of changing the color (adding the rectangle), one could put invisible buttons over the caption headings instead. Keep your present look, but use the button down (just to show it as "clicked") or onclick event to change the caption for that heading with a down (or up) arrow.

Just a thought.
 

Users who are viewing this thread

Back
Top Bottom