?
Solved

Sorting listboxes at runtime

Posted on 2011-03-01
8
Medium Priority
?
287 Views
Last Modified: 2012-05-11
I recently changed oversubforms to listboxes in a database because I needed to have a multi-select ability. Unfortunately the listbox control does not include a method for sorting on different columns at runtime as the subforms did.

I'm thinking of having a button for each column that would create the "ORDER BY" clause of the SQL statement that refreshed the rowsource property.

I figured before I tried to re-invent the wheel I would see if there were any methods to achieve this result.
0
Comment
Question by:wipnav
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 9

Expert Comment

by:McOz
ID: 35011182
Just add the ORDER BY to the rowsource property of each listbox field

This has worked for me - good luck!
0
 
LVL 85
ID: 35011202
There's no builtin functionality for that. You'll have to buildup your ORDER BY clause and reset the RowSource of your Listbox.
0
 
LVL 1

Author Comment

by:wipnav
ID: 35011379
LSM, that is what I was thinking, but I would need to add a command button for each sortable column though?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 35011409
<I recently changed oversubforms to listboxes in a database because I needed to have a multi-select ability. >

you could have added a checkbox field for use in multi selection of items, and still have the sorting capabilities.
0
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 total points
ID: 35011413
I've done this with Labels, and running code on the Click or DoubleClick event of the labels. Command buttons would work as well.
0
 
LVL 75
ID: 35014596
You can also use an Option Group to make the selection, using the AfterUpdate event of the option group to determine with 'sorting' option was selected.

Private Sub frame1_AfterUpdate()
    Select Case 1
         Me.YourListBoxName.RowSource = "SELECT Table1.* FROM Table1 ORDER BY Table1.FIELD1"
    Select Case 2
         Me.YourListBoxName.RowSource = "SELECT Table1.* FROM Table1 ORDER BY Table1.FIELD2"
    Select Case 3
         Me.YourListBoxName.RowSource = "SELECT Table1.* FROM Table1 ORDER BY Table1.FIELD3"
 ' and so on
   End Select

End Sub

mx
0
 
LVL 75
ID: 35014629
minor correction: (not enough sleep last night)

Private Sub Frame1_AfterUpdate()
    Select Case Me.Frame1
       Case 1
         Me.YourListBoxName.RowSource = "SELECT Table1.* FROM Table1 ORDER BY Table1.FIELD1"
       Case 2
         Me.YourListBoxName.RowSource = "SELECT Table1.* FROM Table1 ORDER BY Table1.FIELD2"
       Case 3
         Me.YourListBoxName.RowSource = "SELECT Table1.* FROM Table1 ORDER BY Table1.FIELD3"
 ' and so on for the number of columns ...
   End Select

End Sub

mx
0
 
LVL 1

Author Closing Comment

by:wipnav
ID: 35026637
Thanks LSM, out of all the solutions, this one seems to work the best. A sample that I used was from this tutorial: http://www.comboprojects.com/articles/accSortingList/accSortingListbox.html
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

762 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