Sort a Listbox on a Form

sumdumgai

Registered User.
Local time
Today, 14:23
Joined
Jul 19, 2007
Messages
453
On a Form, there is a Listbox that is populated with records that result from a DoCmd.OpenQuery "SearchQ" when an event occurs.


One of the fields in the ListBox is 'City'. Is it possible, without re-executing the 'SearchQ' query and re-populating the ListBox, to sort the ListBox records on the 'City' field? I could add 'Sort' button or do some other event to initiate the sort but I don't know what VBA code to use. Or, is there a Requery command that I can use to sort the ListBox records on 'City'?


Thanks.
 
No, not possible - best you could do is modify the rowsource

myListbox.rowsource="SELECT * FROM SearchQ ORDER BY City"

but this will effectively re execute SearchQ - and assumes that City is the name of one of the fields returned
 
Thanks islados. I went ahead and put a button on the form. The button modifies the query sql, changing the sort order. It does a rerun of the query that loads the ListBox but it works fine and doesn't take much time.
 

Users who are viewing this thread

Back
Top Bottom