Populate a listbox with folder names

G

Guest

I am writing code in Access that will open a printed to disk text file with
"Monarch", create a database file, append the database to a table, then print
a report based on that database.

I need to open the text file each month from a different subfolder. I want
to read a folder and all its subfolders, populate a listbox so a person can
choose which folder/month they want to use.

I have the following code, but cannot figure out how to populate the listbox
in access. Also the following code only lists the first record. Any help
would be appreciated.

Option Compare Database
Option Explicit
Private Sub Form_Open(Cancel As Integer)
'----- NOTE: SET REFERENCE: "Microsoft Scripting Runtime" must be
selected.

'----- PURPOSE: List all Folders in a Sourcefolder

Call ListFoldersInDirectory("F:\Dolars Reports\")

End Sub

Sub ListFoldersInDirectory(ByVal SourceFolderName As String)

Dim FSO As Scripting.FileSystemObject
Dim SourceFolder As Scripting.Folder
Dim SubFolder As Scripting.Folder
Dim oArray()
Dim counter As Integer

Dim i As Integer

'----- PURPOSE: Lists the folders in SourceFolder

Set FSO = New Scripting.FileSystemObject

Set SourceFolder = FSO.GetFolder(SourceFolderName)


ReDim oArray(SourceFolder.SubFolders.Count - 1)

For Each SubFolder In SourceFolder.SubFolders

List0.RowSource = SubFolder.Name
Next SubFolder



End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top