By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,493 Members | 1,351 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,493 IT Pros & Developers. It's quick & easy.

How to sort a table or a listbox based on a certain feild/column

P: 4
Hi,
I am using a listbox to show data from a certain table, i want the user, after the listbox is filled, to be able to sort the data according to the column of his choice. I could sort the table and refresh the form, or directly sort the listbox. How can i do any of that without having to open the table?

I also tried to use a subform that shows the table, that way the user can right click on the column and sort, but the problem is that after closing the form, access asks me if i want to save changes made to the table. How can i get rid of this popup menu?

Thanks in advance for any help
Dec 17 '07 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 374
The way to get around it is like this.

You create button on the form that will allow the use to sort by whichever button they push.

When the Click event happens for each of the buttons, you simply pass a SQL String to the Listcontrol under the property of .RowSource = sqlStr. Then simply do a me.listcontrolname.requery and me.repaint and that's it.

If you would like that coded out, let me know.


Hope that helps,

Joe P.
Jan 5 '08 #2

missinglinq
Expert 2.5K+
P: 3,532
The fact of the matter is that you're having trouble doing this because you're trying to use an Access control for something that it's not designed to do!

Listboxes
are intended to be used to select data that will then, either directly or indirectly, be used to add data to a record! They are not intended to be used to simply display data! This is why Access doesn't provide a way to sort them by columns!

This is akin to buying an Ferrari and wondering why you can't plow your garden with it!


Linq ;0)>
Jan 5 '08 #3

P: 4
The way to get around it is like this.

You create button on the form that will allow the use to sort by whichever button they push.

When the Click event happens for each of the buttons, you simply pass a SQL String to the Listcontrol under the property of .RowSource = sqlStr. Then simply do a me.listcontrolname.requery and me.repaint and that's it.

If you would like that coded out, let me know.


Hope that helps,

Joe P.

Hi Joe,
thanks for your help i appreciate it a lot.
well i did as u said:
listcontrolname.rowsource = sqlStr
me.listcontrolname.requery
me.repaint

but it only empties the list! any ideas?

thanks again for your help
Jan 28 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.