Sorting an array or listbox

  • Thread starter Thread starter Joe Holzhauer
  • Start date Start date
J

Joe Holzhauer

I have a listbox that I'd like to sort alphabetically. Is there a built-in
routine that will do this for me? I wrote some code myself that works
(well, if I do say so myself!), but I wonder if something built-in would be
more efficient.

Alternatively, it's a "value list" that I could copy into an array and sort
the array.

Any ideas?

Thanks,
Joe
 
Use a query as the row source for the listbox, and include an Order By
clause in it to sort the data the desired way.
 
Hi Joe

As Ken says, you can sort a "Table/Query" rowsource with an order by clause,
but as yours is a Value List there is no built-in method.

The easiest way is, as you say, to copy it to an array and sort it there.
You can use the Split and Join functions to create the array from the
RowSource and vice-versa:

Dim aRowSource as variant
aRowSource = Split( MyCombo.RowSource, ";" )
Call MyFavouriteSortProcedure aSource
MyCombo.RowSource = Join( aRowSource, ";" )
 
Graham Mandeno said:
Hi Joe

As Ken says, you can sort a "Table/Query" rowsource with an order by
clause, but as yours is a Value List there is no built-in method.

Ack....I missed that info. Thanks for the catch, Graham.
 
Back
Top