Results 1 to 10 of 10
  1. #1
    Jmccomas is offline Novice
    Windows 11 Office 365
    Join Date
    Mar 2023
    Posts
    4

    Combo Box with edit List

    How do you sort a combo box that uses an edit list?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Can you provide some sample data/combo?

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    If you mean when you're using an Edit List Items form then base the list on a query that sorts your list items the way you want. When you close that form, requery the combobox.
    See Enter data by using a list
    https://support.microsoft.com/en-us/...e-07d7200980ce

    but think twice before using a multi value list
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Jmccomas is offline Novice
    Windows 11 Office 365
    Join Date
    Mar 2023
    Posts
    4
    Thanks for the responce but I am using a Combo Box that saves list for later use. Not using a query for the source.

    Click image for larger version. 

Name:	Access.jpg 
Views:	15 
Size:	80.0 KB 
ID:	50037

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    OK, then you will have to edit that list manually. If you have A;B;C;G;H;I and you want to interject D;E;F in the correct sequence, put the cursor after C, hit return and type D on the new line and so on. Or you can open the form with the combo box in design view and edit the list in the property sheet. VBA code would be a much more complicated solution.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    If you really want to sort the combo's actual value list instead of creating a lookup table, then put this in a code module:

    Code:
    Option Compare Database
    Option Explicit
    
    
    Dim newArray() As String
    
    
    Public Sub BubbleSort(sourceArray() As String, MaxItem As Long)
        Dim strTemp As String, i As Long, j As Long
        For j = 0 To MaxItem - 1
            For i = 0 To MaxItem - 1
                If sourceArray(i) > sourceArray(i + 1) Then     'swap
                    strTemp = sourceArray(i)
                    sourceArray(i) = sourceArray(i + 1)
                    sourceArray(i + 1) = strTemp
                End If
            Next i
        Next j
        newArray = sourceArray
    End Sub
    
    
    Public Sub FormMod(fName As String, cboName As String)
        DoCmd.OpenForm fName, acDesign
        '  "OUTBACK";"TRIM";"PLANT";"CLEAN";"SHIP+";"HANG";"PRE-BOOK";"EMPTY";"SPACE";"MOVE";"TOP DRESS"
        Dim aList() As String, i As Long
        Dim SortedRowSource As String
        Dim nLen As Long
        aList = Split(Forms(fName).Controls(cboName).RowSource, ";")
        nLen = UBound(aList)
        Call BubbleSort(aList, nLen)
        For i = 0 To nLen
            If Len(newArray(i)) > 0 Then
                SortedRowSource = SortedRowSource & newArray(i) & ";"
            End If
        Next
        'Debug.Print SortedRowSource
        Forms(fName).Controls(cboName).RowSource = SortedRowSource
        DoCmd.Close acForm, fName, acSaveYes
    End Sub
    Then at BOJ, call the code like this from the autoexec macro, or in the open event of your main form (not the target form).

    call FormMod("frmExample","cboList")

    The call requires 2 parameters, the form name and the combobox name.

    Before
    Click image for larger version. 

Name:	before.png 
Views:	10 
Size:	12.9 KB 
ID:	50040

    After
    Click image for larger version. 

Name:	after.png 
Views:	10 
Size:	13.5 KB 
ID:	50041

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I don't see the point of all that, but maybe that's just me. What is shown in post 4 is a highly simplified and built in version of all that code and form, and does not use a lookup table either. Perfect enough for value list items IMO, but I consider queries with lookup tables the way to go. Much more versatile.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Quote Originally Posted by Micron View Post
    I don't see the point of all that, but maybe that's just me. What is shown in post 4 is a highly simplified and built in version of all that code and form, and does not use a lookup table either. Perfect enough for value list items IMO, but I consider queries with lookup tables the way to go. Much more versatile.
    If items need be added manually, just use the built in editor to add to the bottom and the list will be sorted at next BOJ. Saves you the trouble of a manual rearrange.
    However, as stated, I wouldn't do it this way. I would use a lookup table and a Not-in-List event for the combo.

  9. #9
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    If items need be added manually, just use the built in editor to add to the bottom and the list will be sorted at next BOJ
    Or put cursor where you want to add an item below, hit enter, type in item - done. No editing form, no BOJ procedures to maintain?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Still be helpful if list is large and unsorted.

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

Similar Threads

  1. How to edit a list in access
    By JamesH89 in forum Access
    Replies: 1
    Last Post: 12-27-2018, 10:07 AM
  2. combo-box list items edit form
    By raffi in forum Forms
    Replies: 3
    Last Post: 10-26-2014, 03:22 PM
  3. Replies: 8
    Last Post: 05-14-2012, 09:49 AM
  4. not in edit list
    By Andyjones in forum Programming
    Replies: 2
    Last Post: 04-16-2012, 11:40 PM
  5. Edit List Items
    By Broderhol in forum Forms
    Replies: 3
    Last Post: 02-23-2011, 05:51 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