Solved

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

Posted on 2007-04-10
15
270 Views
Last Modified: 2008-02-01
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.
0
Comment
Question by:Mike Eghtebas
  • 7
  • 5
  • 3
15 Comments
 
LVL 75
ID: 18885952
In the same list box, right?

mx
0
 
LVL 75
ID: 18885966
Also, is the list populated from a qry or SQL in the row source?

mx
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 18885997
Yes, the same listbox. The rowsource is populated via a query. Which reads its data yet from another query.

Mike
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 34

Expert Comment

by:jefftwilley
ID: 18886421
how many columns Mike?
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 18886847
One column.
0
 
LVL 75
ID: 18886867
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
 
LVL 34

Assisted Solution

by:jefftwilley
jefftwilley earned 150 total points
ID: 18887122
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
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 350 total points
ID: 18887164
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
 
LVL 34

Expert Comment

by:jefftwilley
ID: 18887242
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
 
LVL 75
ID: 18887302
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
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 18887588
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
 
LVL 75
ID: 18887710
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
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 18894256
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
 
LVL 75
ID: 18894308
"How about chaging its setting to a UserDefined function "

Not sure what you mean?

mx
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 18894381
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

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question