• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 774
  • Last Modified:

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!
Jarred Meyer
Jarred Meyer
  • 3
  • 2
1 Solution
Dale FyeCommented:
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 & "*")
        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:\")
Jarred MeyerProduction ManagerAuthor Commented:
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?
Dale FyeCommented:
Yes,  I explicitly added a "\" to the end of the folder name, then used the Replace function to replace dups of "\\" on the off chance that the user were to add the "\" to the end of the path.

Try changing:

    strPath = Replace(Folder & "\", "\\", "\")


    strPath = Replace(Folder & "\", "\\", "\", 3)

That should start the replace at the 3rd character, which should resolve the issue you are encountering by using the fully qualified network path.
Jarred MeyerProduction ManagerAuthor Commented:
Thanks fyed!
Dale FyeCommented:
glad I could help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now