Listbox, sort selected items first then... Ms Access

I have a code which selects, say, 20 out of 50 items from a list box. These 50 items are sorted alphabetically (regardless they are selected or not).

I am looking for code to display the selected items first (sorted) followed by the rest (sorted).

How this can be done?

Thanks.
LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
In the same list box, right?

mx
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Also, is the list populated from a qry or SQL in the row source?

mx
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Yes, the same listbox. The rowsource is populated via a query. Which reads its data yet from another query.

Mike
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

jefftwilleyCommented:
how many columns Mike?
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
One column.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
And so ... then after you made the selections, you would click a button and that would resort the list in the manner specified?

mx
0
jefftwilleyCommented:
Mike, we need to see the code that "selects" the 20 out of 50. I think we're either going to have to load the selections into an array, or a temp table, to sort them, then feed them back to the listbox as a field list. Seems the easiest to me.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Probably ... if I was going to do this ... the drift would be:

I would have a sort flag in the underlying table
I would read the selected items and then one way or another, using that info (keys, etc) I would:
1) Run an update query and clear the sort flag field
2) run an update query and set the Sort field to True
3) Apply the SQL/query to the RowSource of the list box ... resulting in the desired sort.  

I pretty much do that in a report engine I have ... involving multi-select list boxes for criteria selection.  One of the features is that the user can sort the list by the different columns (if there are more than one).  And the cool thing is ... when you apply the new query ... the same items are still selected!

This works pretty well for maybe 100-200 items max in the multi-select list box.  The multi-select list box has some performance issues when you start loading several 100 items, clearing, selecting All, etc.

You might look at :

http://www.dbi-tech.com/ctList.asp

This company makes some VERY cool stuff.  I've user their tree view control in Access ... and it's 125.83 times better and cooler than the Access tree view control ... not to mention ... it has DOCUMENTATION !!!

So ... you spend a little money ... and you get a LOAD of very cool tools!

mx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jefftwilleyCommented:
The "harvest" of the selected items in the listbox, would then have to be queried out of the remaining 50. You have to have a way to keep them separated while you sort them....then simply write them to the table in with the 20 sorted items first, then the remaining 30 below that.

To break down the steps involved?

1) something triggers your code to run that selects the 20 items.
2) as soon as that happens, we transition into the sorting routine
3) the items are put back into the listbox in the order you want
4) Are the 20 items still selected at this point?
5) The user can now select different items than the original 20 if he wants
6) the user pushes a button, or some other event fires to do something with the Newly selected items
7) What happens with the list NOW? Another sort order loop for the top 20 again?
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
jw ... are you asking me or him?

fwi ... House and Boston (ill)Legal will be on shortly ... so, I will be intermittent, if not incoherent, lol ...
Can you hold it down ok?  Man ... it's like only you and I are on duty today.  Hey ... only 10.8K more pts ... and I hit the jackpot, lol ... and I git to print out another cool 'diploma'  :-)

mx
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
I will go over your comments tomarrow. But, I want to let you know all items in the list box are sorted to begin with like:

Adam
Ben
Cindy
David
.
.

If user selects Ben and David and then fires the code in question, it is expected to deliver:

Ben         'selected
David      'selected
Adam
Cindy
.
.

In VB, I guess one could read them in array and repopulate the combo box according to their index.  Here we will see what are the possibilities.

Thank you,

Mike
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Yes .... I understand what you want ... and it's a cool idea and makes sense.  Sadly, nothing in the list box inherently makes this easy to do.  The concept is simple, but just a bit of work to implement.

mx
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
How about chaging its setting to a UserDefined function (run-time) where you can populate back the list box in any fashion (order) is is desired?

Mike
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
"How about chaging its setting to a UserDefined function "

Not sure what you mean?

mx
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Basically there are four ways to populate a list box:

RowSource Type
- Table/Query
- Value List
- Field List
- UserDefinedFunction.

With the last one, although not part of options provided, you type:

=fnMyListBox()

for RowSource Type and leave the rowsource itsel blank. From Access help, you could see how a user defined function like this gets to be populated (very powerful, I have use it to maintain 2,500,000 items in a list box).

Mike
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.