Results 1 to 6 of 6
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097

    sort order of FSO.GetFolder

    Is there a way to specify that FSO.GetFolder return the list of folders in numerical sort order? The module I just created works just fine, but the names found are not sorted numerically.



    Code:
    Public Function DirFolders(strDirectory As String, Optional Req As String)
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  Find the names of folders in a directory.  Optionally, restrict
    '  the names returned to folder names that contain a sub-string.
    '  In either case, the names are returned as a semicolon delinated
    '  list.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Dim objFSO As Object
    Dim objFolders As Object
    Dim objFolder As Object
    DirFolders = ""
    
    
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objFolders = objFSO.GetFolder(strDirectory).SubFolders
      
        For Each objFolder In objFolders
            If Not IsMissing(Req) Then
                If InStr(objFolder.Name, Req) > 0 Then _
                    DirFolders = DirFolders & objFolder.Name & ";"
            Else
                DirFolders = DirFolders & objFolder.Name & ";"
            End If
        Next objFolder
    
    
    Set objFSO = Nothing
    Set objFolders = Nothing
    Set objFolder = Nothing
    
    
    End Function

  2. #2
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I'd say no if you mean directly from the folder/subfolders looping, but let's see what smarter people say. These folders have full/partial numeric names? Then create a recordset sorted by sql that has an Order By clause?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    I thought as much. What I was up to was to create a value list for a combo. I'll load up a temporary table and let SQL furnish the combo with a sorted RecordSource.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,558
    Another way might be to use the old DIR command and write the output to a file, then read that?

    https://learn.microsoft.com/en-us/wi...s-commands/dir
    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

  5. #5
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    Would help to know what the actual folder names look like.
    You mention numerical but the folder names would be text and sort like text.

    When I debug.print subfolder names in a folder with normal non-numerical names they sort in alphabetical order.

    I also think that your "Optional Req As String" should be "Optional Req As Variant" in order for IsMissing to function properly.

    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  6. #6
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    Here's an example of sorting folders using a dictionary.
    Can't get more specific without knowing what your folder names look like but if they need to be fudged you can do that in the item of the dictionary and sort by that.
    note: need reference to MS Scripting runtime and MS Office XXX object library.

    EDIT: also just noticed that your instr() syntax is incorrect.
    Attached Files Attached Files
    Last edited by moke123; 07-15-2024 at 10:43 AM.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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

Similar Threads

  1. ORDER BY sort order?
    By TOPSie in forum Queries
    Replies: 4
    Last Post: 04-23-2021, 03:25 AM
  2. Replies: 5
    Last Post: 08-27-2019, 08:41 AM
  3. Sort Order problem
    By Chris@harveynorman in forum Reports
    Replies: 8
    Last Post: 11-22-2016, 10:42 PM
  4. Sort by Month Order
    By sk88 in forum Reports
    Replies: 1
    Last Post: 03-17-2015, 05:22 PM
  5. Sort order in a sub form
    By roar58 in forum Forms
    Replies: 1
    Last Post: 03-17-2012, 08:57 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