Solved

filelistbox > name and date sort

Posted on 2003-12-07
3
1,149 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

696 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