Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211

    Access 2016 ListBox not Sorting Properly

    I have a ListBox on my Access form to find and select a record from the bound table. Here is the ListBox's RowSource:

    Code:
    SELECT SGID, SGGroupName, SGCategory FROM tblSGroups ORDER BY SGGroupName;
    If I execute that query in the query window, I get the following result (which I've scrolled a bit to show pertinent records):

    Click image for larger version. 

Name:	Screenshot 2023-02-07 171550.png 
Views:	40 
Size:	40.9 KB 
ID:	49644

    When I view the ListBox on the form, I get the following (also scrolled to the right entry):



    Click image for larger version. 

Name:	Screenshot 2023-02-07 171717.png 
Views:	39 
Size:	15.1 KB 
ID:	49645

    Note the 2 entries at the end are out of order. I can't figure this out. Why would 2 random records show up out of order?
    They ARE the last 2 entries I put into the table, but they should be showing alphabetically, right?

    Any ideas? Thanks...

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Look for hidden characters.
    How did you add those two. Compared against the rest?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Try retyping the data for those two records.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Thanks for the replies. I can't find any special characters. I went into the underlying table and found the records and re-typed the names. Same thing. Works fine if I execute the query, but not in the ListBox which has the query in the underlying rowsource.

    I added the 2 records through an import process where they give me an Excel workbook which I link to as a temporary table, then update the data into the permanent table using VBA. Even if the import process caused this, re-typing the names directly in the table after clearing the fields should have fixed that. So I don't think it's a hidden character. There's something strange about the ListBox that is causing this.

    If I can't get this worked out, I think I will have to use a continuous subform instead of the listbox. The oly reason I need this is to quickly jump to the desired record by picking it out of a list.

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Can you please show us the list box in design view with the property box showing the row source and the column number\widths (probably need to take 2 screenshots)?

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    The problem might be with the other records. If they have a leading space, they will sort first.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Quote Originally Posted by Gicu View Post
    Can you please show us the list box in design view with the property box showing the row source and the column number\widths (probably need to take 2 screenshots)?

    Cheers,
    Click image for larger version. 

Name:	Screenshot 2023-02-09 095512.png 
Views:	30 
Size:	22.0 KB 
ID:	49652Click image for larger version. 

Name:	Screenshot 2023-02-09 095554.png 
Views:	30 
Size:	22.2 KB 
ID:	49653

  9. #9
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Quote Originally Posted by Micron View Post
    The problem might be with the other records. If they have a leading space, they will sort first.
    If that were the case, wouldn't they also show in the same wrong order when the query is executed in the query design window?

  10. #10
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Quote Originally Posted by June7 View Post
    If you want to provide db for analysis, follow instructions at bottom of my post.
    Thanks June7. I can take the single table and form and copy them to a new database and submit that. I will do that if I don't soon receive an answer on this thread.

  11. #11
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Can't see anything wrong in the screenshots, but can you please try to save the query that gives you the right results and use that in the row source (just selected from the queries tab when you click the builder on the right) and see what happens?

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  12. #12
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Quote Originally Posted by RMittelman View Post
    If that were the case, wouldn't they also show in the same wrong order when the query is executed in the query design window?
    I would expect as much, but a query behaving differently than a listbox was the only thing I could think of.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  13. #13
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Quote Originally Posted by Gicu View Post
    Can't see anything wrong in the screenshots, but can you please try to save the query that gives you the right results and use that in the row source (just selected from the queries tab when you click the builder on the right) and see what happens?

    Cheers,
    I thought that was just what I did. If you click on the ellipsis next to Row Source, it opens the query designer with that query. Running the query there shows the records in the proper order. With no changes at all to the Row Source query text, opening the form in form view shows the records in the wrong order.

  14. #14
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    That is not what I meant. In the query designer create a new query with the same SQL statement as the current one in the row source of the listbox. Run it and confirm it returns the properly sorted records. If yes save the query naming it qrySortedList or similar. Now in design view if the form open the properties window for the listbox and in the Row source line simply enter qrySortedList. Save the form and open it in form view and check the sort order.

    Cheers,

  15. #15
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Quote Originally Posted by Gicu View Post
    That is not what I meant. In the query designer create a new query with the same SQL statement as the current one in the row source of the listbox. Run it and confirm it returns the properly sorted records. If yes save the query naming it qrySortedList or similar. Now in design view if the form open the properties window for the listbox and in the Row source line simply enter qrySortedList. Save the form and open it in form view and check the sort order.

    Cheers,
    Well, seems it should work whether you have a saved named query or not. The SQL code in the row source, pasted into the query designer SQL view, returns the records properly sorted. Shouldn't have to save it and use the saved query name. However, I did that and it still didn't work, the 2 problem records are still at the bottom. Definitely seems like something with the ListBox. But thanks for trying...

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 03-25-2019, 12:59 AM
  2. Replies: 4
    Last Post: 08-07-2018, 05:38 AM
  3. Properly Displaying Special Characters in ListBox
    By ohmydatabase in forum Access
    Replies: 17
    Last Post: 07-22-2017, 06:33 PM
  4. Reports not sorting properly
    By Nick Lingenfelter in forum Reports
    Replies: 10
    Last Post: 02-26-2013, 06:38 PM
  5. Time not Sorting Properly in Report
    By KrenzyRyan in forum Reports
    Replies: 3
    Last Post: 06-24-2011, 08:56 PM

Tags for this Thread

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