I have the following code to fill a listbox with file names.
I can not get it to sort it, I found a script but it errors on .list
Fill the listbox
Sort - not working
I can not get it to sort it, I found a script but it errors on .list
Fill the listbox
Code:
Me.Listbox1.RowSource = ""
Dim MyFolder As String
Dim MyFile As String
'Dim j As Integer
MyFolder = "C:\dbase"
MyFile = Dir(MyFolder & "\*.accdb")
Do While MyFile <> ""
Listbox1.AddItem MyFile
MyFile = Dir
Loop
Code:
Dim i As Long
Dim j As Long
Dim temp As Variant
With Me.Listbox1
For j = 0 To Listbox1.ListCount - 2
For i = 0 To Listbox1.ListCount - 2
If .List(i) > .List(i + 1) Then
temp = .List(i)
.List(i) = .List(i + 1)
.List(i + 1) = temp
End If
Next i
Next j
End With