Solved

filelistbox > name and date sort

Posted on 2003-12-07
3
1,120 Views
Last Modified: 2012-06-27
I want to be able to sort a filelistbox (named file1) ascending and descending at name and date.

How can that be achieved ?
0
Comment
Question by:saskia
  • 2
3 Comments
 
LVL 6

Expert Comment

by:prasitlee
ID: 9891963
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.
                                                      Meng
0
 
LVL 5

Accepted Solution

by:
mccainz2 earned 125 total points
ID: 9892150
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
   
    objRetRS.Open
   
    If objFSO.FolderExists(sFolder) Then
        Set objFolder = objFSO.GetFolder(sFolder)
    Else
        GoTo err_exit
    End If
   
    For Each objFile In objFolder.Files
        objRetRS.AddNew
            objRetRS.Fields("FileName") = objFile.Name
            objRetRS.Fields("FileDate") = objFile.DateLastModified
        objRetRS.Update
    Next
   
    objRetRS.Sort = "FileDate,FileName"
    objRetRS.MoveFirst
   
    While Not (objRetRS.EOF)
        List1.AddItem objRetRS("FileName")
        objRetRS.MoveNext
    Wend
   
    LoadFiles = True
   
err_exit:
End Function
0
 
LVL 5

Expert Comment

by:mccainz2
ID: 9892159
Regarding sybtax for Ascending and descending sorting ...
For example
 objRetRS.Sort = "FileName DESC,FileDate ASC"
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now