Link to home
Start Free TrialLog in
Avatar of Jeremy Campbell
Jeremy CampbellFlag for United States of America

asked on

Populate combobox in access form with filenames from folder.

Just trying to see if there is an easy way to have the list in a combobox be populated from all the filenames in a specific folder?

Thanks in advance for the help!
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

You could use a function to get the names of all the files on a path:
Public Function fnGetFilenames(Folder As String) As String

    Dim strPath As String
    Dim strFileName As String
    
    strPath = Replace(Folder & "\", "\\", "\")
    
    strFileName = Dir(strPath & "*")
    Do
        fnGetFilenames = fnGetFilenames & ";" & strFileName
        strFileName = Dir()
    Loop While Len(strFileName) > 0
    
    If Len(fnGetFilenames) > 0 Then fnGetFilenames = Mid(fnGetFilenames, 2)
    
End Function

Open in new window

Then, change the RowSourceType property of the combo box to "Value List" and use the forms Load event to populate the RowSource of the combo box, something like:

me.comboFilenames.RowSource = fnGetFilenames("C:\")
Avatar of Jeremy Campbell

ASKER

thanks for the prompt response!

I'm hung up though;

I think the replace code is doing something to my path.

Here is my path;
Me.cboFiles.RowSource = fnGetFilenames("\\sfile0\e\cnc\HURCO Tool Lists\Tool List\")

Is it changing that "\\" to a single "\" and can that be changed somehow?
ASKER CERTIFIED SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks fyed!
glad I could help.