[Webinar] Streamline your web hosting managementRegister Today


FileSystemObject Search subfolders

Posted on 2004-10-22
Medium Priority
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

jjafferr earned 2000 total points
ID: 12385198
Hi BillPowell,

Here you go:

I hope this helps.

LVL 11

Author Comment

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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
Implementing simple internal controls in the Microsoft Access application.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…
Suggested Courses

612 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