Results 1 to 7 of 7
  1. #1
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    154

    Order a list box in Access


    Is it possible to order a list box in access by tems that are selected (i.e. selected(i)=true) to be at the top?

    The row source of my list box is a table.

    But then I am looping through the items in the list box and selecting a few.

    I then want the ones that I selected to be at the top.

  2. #2
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    Ignore me - I mis read the intention 1
    Last edited by Minty; 04-05-2019 at 01:48 AM.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    your method would require lots of code.
    an alternate method would not. Instead of 1 multi-select box, use 2 listboxes:
    1 source list (to pick from)
    1 target list (chosen items)

    I have a tPicked table so when the user dbl-clicks an item in the 'Available' list, it runs an append query and adds it to the 'Picked' list. (tPicked table)
    no code needed.
    You can even reduce the Available list by using an outer join query so the available list only shows what was Not in the Picked list.

  4. #4
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Ranman's solution is certainly valid.

    But it wouldn't require lots of code to do what you said.
    Add a hidden boolean field to your list.
    In your listbox after update event, set the field true for items you select.
    Then use a button_click event to update the listbox row source to sort by the Boolean field then by whatever field its normally sorted by.

    You could do the re-sorting as well on your after update event but I think it would be confusing if the order changed on each click.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  5. #5
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    But then I am looping through the items in the list box and selecting a few.
    Just to be clear, are you selecting the items in the list by clicking on them or are you iterating (looping) through the list box and setting certain items selected = true using code?

  6. #6
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    Seconded Ranman's answer.

    A more common way of doing this (and more visually appealing) would be to "move" the selected items to another list, then run your actions against the second list.
    I used a similar technique to select Employees I wanted to bulk update training records for. It was a long multi select list so you couldn't easily see who you had selected.

    Moving them to another list made it obvious.

    There is a demo here https://access-programmers.co.uk/for...d.php?t=165776
    And a video to demonstrate here : https://www.google.com/search?q=acce...TF-8#kpvalbx=1
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  7. #7
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    With the demo by David Crake in Minty's post, you may get a warning about a missing reference to DatGrid.
    Its not needed and can be removed.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 03-26-2019, 06:00 AM
  2. Replies: 5
    Last Post: 01-31-2019, 02:09 PM
  3. Replies: 2
    Last Post: 03-07-2016, 05:02 PM
  4. order multiple columns in list box
    By Dachbo in forum Forms
    Replies: 2
    Last Post: 07-13-2015, 06:45 PM
  5. Replies: 8
    Last Post: 05-16-2014, 12:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums