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],[DateCr eated],[Da teLastModi fied],[Hyp erlink]) 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
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],[DateCr
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!!!