Using Query to List File names in specified directory

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am looking to have a combo box on a form which displays every file name
which is a .csv file within a specified directory, which will always be the
same directory on the hard drive.

I believe this can be accomplished through a SQL statement that is run when
the control is enabled, but I do not know where to start.

Any assistance would be appreciated.
 
I don't know a way of accessing the file system via SQL, but here's a
different can of worms:

Function GetFilesAsValueList(FolderPath As String, _
FileType As String) As String
'Returns files of specified type from specified folder
'as a list suitable for the rowsource of a listbox
'or combobox
'By John Nurick 2005
Dim oFS As Object 'Scripting.FileSystemObject
Dim oFolder As Object 'Scripting.Folder
Dim oFile As Object 'Scripting.File
Dim strList As String
Const strDELIMITER = ";"

Set oFS = CreateObject("Scripting.FileSystemObject")

Set oFolder = oFS.GetFolder(FolderPath)

If oFolder.Files.Count > 0 Then
For Each oFile In oFolder.Files
If oFS.GetExtensionName(oFile.Name) = FileType Then
strList = strList & oFile.Name & strDELIMITER
End If
Next
If Len(strList) >= 1 Then
GetFilesAsValueList = Left(strList, Len(strList) - 1)
End If
Else
GetFilesAsValueList = ""
End If
Set oFolder = Nothing
Set oFile = Nothing
Set oFS = Nothing
Exit Function
End Function
 
Back
Top