[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Populate combobox in access form with filenames from folder.

Posted on 2012-08-31
5
Medium Priority
?
748 Views
Last Modified: 2012-09-04
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!
0
Comment
Question by:SeyerIT
  • 3
  • 2
5 Comments
 
LVL 49

Expert Comment

by:Dale Fye
ID: 38354453
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:\")
0
 
LVL 2

Author Comment

by:SeyerIT
ID: 38354995
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?
0
 
LVL 49

Accepted Solution

by:
Dale Fye earned 2000 total points
ID: 38355275
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 & "\", "\\", "\")

to:

    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.
0
 
LVL 2

Author Closing Comment

by:SeyerIT
ID: 38363206
Thanks fyed!
0
 
LVL 49

Expert Comment

by:Dale Fye
ID: 38364606
glad I could help.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question