Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to sort a list box by clicking on a column

Status
Not open for further replies.

stupiet

Programmer
Aug 21, 2001
176
US
To anyone who can help,

I created a listbox that lists the item number, date of entry, and cost.

I want the user to have the ability to sort any way they want to by simply clicking on a textbox that sits above the column. So if they click on the textbox above the item number column, that column will sort in increasing order. If they click again it will sort in decreasing order. The same should happen when they click on date and cost.

Is there a way to do this?

Thanks,

Stupiet
 
Hello,
Does your listbox have a query as its source? If so, you could write some code that goes behind the "click event" that does the following:

1. Grab sql from listbox.
2. Check if you find "ORDER BY" ...
a. if not found, add "Order By <fld> ASC".
b. if found, check if same data field name; toggle ASC / DESC dependong on what you found.



35+ years of 'progress' -- can't we all just go wire boards again?
 
Thanks for the tip Trevil,

I understand what you mean but unfortunately I'm not great at writing code. Is there a sample code that you know of that I can copy?

Thanks
 
Thanks Trevil!!!

That should do the trick...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top