Solved

sort unbound multi-column listbox without ORDER BY

Posted on 2008-10-21
7
516 Views
Last Modified: 2013-11-29
I have a multicolumn listbox with 7 columns.  The listbox is a VALUE LIST, therefore not bound to a query.  I would like to have a button, say for example, to sort ascending by the 2nd column, hit it again and it'll sort descending.

Is there a way to do this in Access, perhaps in memory opposed to filling a temporary table, sorting, then repopulating the listbox?

Thanks,
NC
0
Comment
Question by:NO_CARRIER
  • 4
  • 3
7 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 22766558
No recordset = No sorting.  Sorry dude.
Just slam all your values in a table, then create a query that reads them.

If all this is is a simple list of user-selectable choices, memory is insignificant.
0
 
LVL 1

Author Comment

by:NO_CARRIER
ID: 22766595
Will the temporary tables be stored in the front-end by default, and cleaned up with compact on exit?.. or will I need to keep an eye on the back-end database to compact it regularly?
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 22766610
>Will the temporary tables be stored in the front-end by default
All depends on your preference.  If you want immediate control over it because of updates, put it in the back-end.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:NO_CARRIER
ID: 22766649
I found the following solution, which works with only a single column listbox... but having a tough time modifying it for a multicolumn listbox...

Private Sub cmdSort_Click()
    Dim FinishedSwapping As Boolean
    Dim UpperBound As Long
    Dim Temp As String
    Dim strValue() As String
    Dim i As Long
   
    'Add each value in the list to a temporary array (for sorting)
    For i = 0 To lstBox.ListCount - 1
        ReDim Preserve strValue(i)
        strValue(i) = lstBox.ItemData(i)
    Next i

    UpperBound = UBound(strValue())

    'Sort array into ascending order
    Do
        FinishedSwapping = True
        For i = 0 To UpperBound - 1
            'If they are bigger then perform a swap
            If strValue(i) > strValue(i + 1) Then
                Temp = strValue(i + 1)
                strValue(i + 1) = strValue(i)
                strValue(i) = Temp
                FinishedSwapping = False
            End If
        Next i
    Loop While Not (FinishedSwapping)

    'Clear list
    lstBox.RowSource = ""
    lstBox.Requery
   
    'Add sorted items into list
    For i = 0 To UpperBound
        lstBox.AddItem strValue(i)
    Next i
End Sub
0
 
LVL 1

Author Comment

by:NO_CARRIER
ID: 22766664
> All depends on your preference.  If you want immediate control over it because of updates, put it in the back-end.

I'm not worried about updates.  So I would build the table in the FE then I suppose.  I'll experiment with this too...
0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 150 total points
ID: 22766684
>I found the following solution, which works with only a single column listbox
In my opinion, this is more work than is necessary.  Just throw them in a table.
In addition to the sorting, the data will be easier to support as you can affect it via SELECT/UPDATE/DELETE/INSERT queries, instead of fishing in form control properties.
0
 
LVL 1

Author Comment

by:NO_CARRIER
ID: 22767060
What is the easiest way of populating a local query with a query from the backend, where the data can be sorted / arranged as required.  I don't want to query the back end every time the user decides to apply an order by clause.

(Note the temporary table/query does not need to be updatable, it's only used to view data.)
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now