Re: Populate a listbox with folder names

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Graham Mandeno (Graham.Mandeno_at_nomail.please)
Date: 08/11/04


Date: Thu, 12 Aug 2004 09:42:49 +1200

Hi Robert

Instead of reinventing the wheel, why not use the "Browse for folder" dialog
that is built into Windows?

You will find sample code at http://www.mvps.org/access/api/api0002.htm

If you also want to give the user flexibility in naming the file, as well as
selecting the folder, then try the built-in "File Save as" dialog (sample at
http://www.mvps.org/access/api/api0001.htm)

-- 
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand
"Robert" <Robert@discussions.microsoft.com> wrote in message
news:45F80529-E334-4D42-8864-03A9691DB4C8@microsoft.com...
> 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
> -- 
> Robert
>


Relevant Pages

  • RE: Access to Outlook Public Folder
    ... If the folder is in a sub folder on the public ... Dim ol As New Outlook.Application ... 'Exit the procedure if appointment has been added to Outlook. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Loop through folders
    ... The folder name to skip needs to be set in the Const statement I added just after the Dim statements. ... Const FolderToSkip As String = "SubFolder 1" ... Inside each one from SubFolder 2 through 50, there are 10 workbooks. ...
    (microsoft.public.excel.programming)
  • Re: Speed up moving items
    ... According to your previous sample you should get access to the folder ... start at mailCount, not mailCount-1. ... Dim Items as RdoItems ... Sub Test() ...
    (microsoft.public.outlook.program_vba)
  • Re: How to find specific subfolders
    ... is the kind I wanted to identify contains the parent folder name... ... Rafael ... > Sub Folders() ... > Dim sFolder As String ...
    (microsoft.public.excel.programming)
  • Re: How to find specific subfolders
    ... > Hi Bob! ... > is the kind I wanted to identify contains the parent folder name... ... >> Sub Folders() ... >> Dim sFolder As String ...
    (microsoft.public.excel.programming)