Welcome to MSDN Blogs Sign in | Join | Help

Microsoft Access Team Blog

Get product announcements, tips and tricks, and news directly from the team @ Microsoft.
Sorting a Listbox Using Command Buttons

Today’s guest blogger is Daniel Lamarche. Daniel is the Training Director at ComboProjects, which specializes in providing custom training solutions in Microsoft Office products.

I always thought it was cool to be able to sort a list by clicking the column heading once, for ascending order then once more for descending order.

A while ago I decided to tackle this feature in an Access form.

clip_image002

The buttons above the field names are used to sort the list. The triangle pointing down means the column is in descending order.

Clicking on it again will sort that column in ascending order and the triangle will be pointing up. Like you are used to.

This project required a basic understanding of Access SQL and concatenating strings.

When you configure the Listbox using the Row Source property to specify the data that will appear in the list you are in fact creating a SQL statement.

Read the rest of the article and download a sample database here: http://www.comboprojects.com/articles/accSortingList/accSortingListbox.html

Send your Power Tips to Mike and Chris at accpower@microsoft.com.
Posted: Friday, November 13, 2009 11:28 PM by Mike Stowe
Filed under: ,

Comments

Data Entry Service said:

Nice study but why go to all that trouble when you can just use the form in datasheet view and it's built in?

# November 14, 2009 4:18 AM

dlamarche said:

Well for one I like the fact that the current row is highlighted which for many years Access guru had only clever techniques to do the same. I can double-click the row and have an event respond to it, you can't delete the data, it required no explanation and the buttons are just above the correct column, No toolbar, no ribbon, no fuss.

I am sorry that this solution doesn't impress you that much but all my customers are very happy using this sort of Find form. Also when you type a character on your keyboard the selected row immediately jumps to the first entry (in the first column) starting with that letter. Finally I will add that the user knows at a glance on what field the list is sorted and in what order.

# November 14, 2009 4:34 AM

Vladimir Cvajniga said:

I've been using similar technique since A97 because users wanted to sort records in listboxes by various columns. So I add this functionality when I'm asked for. It would be very nice if this functionality was built in Access's Listbox... something like clickable header, see ListView in VB6.

# November 15, 2009 1:50 AM

Richard Rost said:

This method is a little more advanced, but it gives you more control over the database than just using datasheet view. I've been using (teaching) a similar technique for years. You can also add text boxes above each of the columns to FILTER the results of the listbox by adding WHERE conditions to the SQL dynamically.

# November 16, 2009 11:27 AM

grovelli said:

Richard, do you have a sample database detailing the "add text boxes above each of the columns to FILTER the results of the listbox by adding WHERE conditions to the SQL dynamically." technique?

# November 16, 2009 12:05 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker