Link to home
Start Free TrialLog in
Avatar of Mike Eghtebas
Mike EghtebasFlag for United States of America

asked on

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.
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

In the same list box, right?

mx
Also, is the list populated from a qry or SQL in the row source?

mx
Avatar of Mike Eghtebas

ASKER

Yes, the same listbox. The rowsource is populated via a query. Which reads its data yet from another query.

Mike
how many columns Mike?
One column.
And so ... then after you made the selections, you would click a button and that would resort the list in the manner specified?

mx
SOLUTION
Avatar of jefftwilley
jefftwilley
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
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
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
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
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
"How about chaging its setting to a UserDefined function "

Not sure what you mean?

mx
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