FileSystemObject Search subfolders

Posted on 2004-10-22
Last Modified: 2012-06-21
I have created an applicantion to catalogue files in a folder.  My main procedure is listed below.  However, if possible I would like to include a checkbox option on my form to allow the user to enable searching for files in subfolders.  Any ideas?  

Public Sub CreateFileList(strTable As String, strFol As String)
Dim fs As New FileSystemObject
Dim fol As Folder
Dim fil As File

On Error GoTo ReportError

'Check to see if the table exists and if not create it
If Not DoesTableExist(strTable) Then
  Call CreateFileTable(strTable)
End If
Set fol = fs.GetFolder(strFol)

For Each fil In fol.Files

   CurrentDb.Execute "INSERT INTO " & strTable & " ([Filename],[Size],[DateCreated],[DateLastModified],[Hyperlink]) SELECT """ & fil.Name & """,""" & fil.Size & """,#" & fil.DateCreated & "#,#" & fil.DateLastModified & "#, """ & fil.Path & """"


  On Error Resume Next
  Exit Sub

  Dim msg As String
  If Err.Number <> 0 Then
    msg = "Error in Program" _
      & vbCr & "Error number " & CStr(Err.Number) _
      & " was generated by " & Err.Source _
      & vbCr & Err.Description
    MsgBox msg, vbExclamation, "Error"
  End If
  Resume ExitHere

End Sub
Question by:BillPowell
    LVL 27

    Accepted Solution

    Hi BillPowell,

    Here you go:

    I hope this helps.

    LVL 11

    Author Comment

    Yes it did.  I was totally unaware of the ability to call a procedure recursively.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Anonabox PRO Tor & VPN Router

    PRO is the most advanced way to fortify your privacy and online anonymity by layering the Tor network with VPN services. Use both together or separately, and without needing to download software onto your devices.

    Suggested Solutions

    Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
    A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
    Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
    With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

    913 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now