Link to home
Start Free TrialLog in
Avatar of BillPowell
BillPowell

asked on

FileSystemObject Search subfolders

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 & """"

Next

ExitHere:
  On Error Resume Next
  Exit Sub

ReportError:
  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
ASKER CERTIFIED SOLUTION
Avatar of jjafferr
jjafferr
Flag of Oman image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BillPowell
BillPowell

ASKER

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