Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Developers    Comments List
Upload Images | @Reply | Bookmark | Link | Email | Next Unseen |
Change List Box Item Order
Brian Crawford 
    
4 years ago
I have a unbound single value item list box with a list of field names.  How can I create a button to take the selected item in the ListBox and change its order one higher in the list? (then refresh?)  

For example, if it is the 3rd of 5 in the list, I would like to select it, click a "move up" button and make it appear as the 2nd item in the list of 5.
Kevin Robertson  @Reply  
          
4 years ago
Check out the Automatic Record Numbering video.
Richard Rost  @Reply  
          
4 years ago
If Kevin's suggestion doesn't work for you, let me know. Might make an interesting video.
Kevin Yip  @Reply  
     
4 years ago
If your list box's row source type is "Field List", you can't change the order because the table or query specified in the row source sets the order. But if row source type is "Value List," you can do it with VBA.

On a "Value List", the row source looks something like "Apple;Boy;Cat;Dog;Egg". Turn this string into an array with the Split() function. E.g. arr = Split(ListBox.RowSource, ";"). That makes arr(0) "Apple", arr(1) "Boy", etc.  To move the 4th item up one spot, you just swap the 3rd and 4th items: s=arr(3): arr(3)=arr(4): arr(4)=s. Then you use Join() to re-connect the items: Me!ListBox.RowSource = Join(arr, ";"). No need to requery the list box. But you do need to unselect the item with VBA: Me!ListBox=Null

When the user selects an item on the list box, the list box's AfterUpdate event is run, and the selected item's position is ListBox.ListIndex, assuming multi-select is disabled. The positions are 0, 1, 2, etc. from top to bottom. If no item is selected, Listindex is -1.
Richard Rost  @Reply  
          
4 years ago
What Rabid said is true. If you do have a field list, you can just add a "sort order" field to that table and manipulate it with a little code. See Custom Sort Order. Like I said, this would make a cool little video. I'll add it to my list. :)

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developers.
 

Next Unseen

 
 
What's This?

 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 9/29/2026 3:12:11 PM. PLT: 2s