Question : Populate a listbox with files from a directory

Using AccesXP i need to use a listbox to display the files from a specify directory.

Any suggestions please?

Answer : Populate a listbox with files from a directory

How 'bout:

Private Sub Form_Load()
'// Add a reference to Microsoft Sctipring Runtime
'// To do this, in the VBE, select Tools, references and tick it from the list
    Dim fso As Scripting.FileSystemObject
    Dim fld As Scripting.Folder
    Dim f As Scripting.File
   
    Set fso = New Scripting.FileSystemObject
    Set fld = fso.GetFolder("C:\") '// Change as required
   
    Me.lstMyListBox.RowSourceType = "Value List"
   
    For Each f In fld.Files
        Me.lstMyListBox.AddItem f.Name
    Next
   
    '// Clean up
    Set f = Nothing
    Set fld = Nothing
    Set fso = Nothing
End Sub

Dave
Random Solutions  
 
programming4us programming4us