Solved

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

Posted on 2007-04-10
15
240 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

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
In the same list box, right?

mx
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Also, is the list populated from a qry or SQL in the row source?

mx
0
 
LVL 33

Author Comment

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

Mike
0
 
LVL 34

Expert Comment

by:jefftwilley
Comment Utility
how many columns Mike?
0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
One column.
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 350 total points
Comment Utility
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
Comment Utility
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

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
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 33

Author Comment

by:Mike Eghtebas
Comment Utility
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

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
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 33

Author Comment

by:Mike Eghtebas
Comment Utility
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

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
"How about chaging its setting to a UserDefined function "

Not sure what you mean?

mx
0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now