filelistbox > name and date sort

I want to be able to sort a filelistbox (named file1) ascending and descending at name and date.

How can that be achieved ?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dear saskia,
    If you are using ListBox as the control for showing file, try to change the property "Sorted" to TRUE. All files in FileListBox would be sorted as you needed.
Well , don't think you should use a fileList box for this , I wrote a quickie app using a regular listbox .... code follows
Modify the sort string to get your desired results .

Private Sub Command1_Click()

    If Not LoadFiles("C:\DX9\Lib") Then
        MsgBox "Files failed to load."
    End If
End Sub

Private Function LoadFiles(sFolder As String)

    Dim objFSO As New FileSystemObject
    Dim objFile As File
    Dim objFolder As Folder

    Dim dDate As Date
    Dim objRetRS As New ADODB.Recordset
    Dim strFilter As String
    LoadFiles = False
    objRetRS.CursorLocation = adUseClient
    objRetRS.ActiveConnection = Nothing
    'Set up our columns etc....
    objRetRS.Fields.Append "FileName", adVarChar, 250
    objRetRS.Fields.Append "FileDate", adDate
    If objFSO.FolderExists(sFolder) Then
        Set objFolder = objFSO.GetFolder(sFolder)
        GoTo err_exit
    End If
    For Each objFile In objFolder.Files
            objRetRS.Fields("FileName") = objFile.Name
            objRetRS.Fields("FileDate") = objFile.DateLastModified
    objRetRS.Sort = "FileDate,FileName"
    While Not (objRetRS.EOF)
        List1.AddItem objRetRS("FileName")
    LoadFiles = True
End Function

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Regarding sybtax for Ascending and descending sorting ...
For example
 objRetRS.Sort = "FileName DESC,FileDate ASC"
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.