Function ImportFileDetails() DoCmd.SetWarnings False Dim fs, i, temp As Variant Dim dbs As Database Dim rst As Recordset Dim sql As Variant Dim msoSortByFileName As Variant Dim msoSortOrderAscending As Variant Set dbs = CurrentDb Set fs = Application.FileSearch sql = "D:\Doc Control\ISO\Doc Control\Level 3 QWI\" '(i.e. c:\") On Error Resume Next On Error GoTo 0 Set rst = dbs.OpenRecordset("tblDocListing") With fs .NewSearch .LookIn = sql .SearchSubFolders = False .Filename = "*.*" If .Execute(SortBy:=msoSortByFileName, _ SortOrder:=msoSortOrderAscending) > 0 Then 'MsgBox "There were " & .FoundFiles.Count & _ " file(s) found." For i = 1 To .FoundFiles.Count rst.AddNew rst!DocFilePath = Left(.FoundFiles(i), InStrRev(.FoundFiles(i), "\")) rst!DocFileName = Mid(.FoundFiles(i), InStrRev(.FoundFiles(i), "\") + 1) rst!DocFileSize = FileLen(.FoundFiles(i)) rst!DocFileModified = FileDateTime(.FoundFiles(i)) rst.Update 'MsgBox .FoundFiles(i) Next i Else MsgBox "There were no files found." End If End With rst.Close dbs.Close DoCmd.SetWarnings True End Function
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.