I have a program that will search for files. I only want the 'FileSearch' command to return files that occur after a specified date that the user inputs. I use the 'PropertyTest.Add' method of the 'FileSearch' command and it works, but it takes way too long. In fact, it takes so long that I went to the task manager to end the program. Task Manager indicated that Access was not responding. However, if I just let the program run for a long time it would work. I know that the problem lies within the 'PropertyTest' method because I ran the program excluding that statement and it only took a few seconds. Is there a problem with my code that is making the program run really slow, or is that just the way it is? I appreciate any advice. My code follows:
With Application.FileSearch
.NewSearch
.LookIn = "D:\Shared"
.SearchSubFolders = True
.FileName = "*op*.txt"
'.PropertyTests.Add Name:="Last Modified", Condition:=msoConditionAnytimeBetween, Value:=ModifiedDate, SecondValue:=Date
.Execute
If .FoundFiles.Count > 0 Then
Set newtbl = CurrentDb.CreateTableDef("FoundFiles")
Set fld = newtbl.CreateField("FileName", dbText)
fld.OrdinalPosition = 1
newtbl.Fields.Append fld
CurrentDb.TableDefs.Append newtbl
Set rec = CurrentDb.OpenRecordset("FoundFiles")
For i = 1 To .FoundFiles.Count
rec.AddNew
rec("FileName") = .FoundFiles(i)
rec.Update
Next i
rec.Close
DoCmd.Close acForm, "FileSearch"
DoCmd.OpenForm "FoundFiles"
Else: MsgBox "No new OpLogs were found in the selected directory!"
End If
End With
With Application.FileSearch
.NewSearch
.LookIn = "D:\Shared"
.SearchSubFolders = True
.FileName = "*op*.txt"
'.PropertyTests.Add Name:="Last Modified", Condition:=msoConditionAnytimeBetween, Value:=ModifiedDate, SecondValue:=Date
.Execute
If .FoundFiles.Count > 0 Then
Set newtbl = CurrentDb.CreateTableDef("FoundFiles")
Set fld = newtbl.CreateField("FileName", dbText)
fld.OrdinalPosition = 1
newtbl.Fields.Append fld
CurrentDb.TableDefs.Append newtbl
Set rec = CurrentDb.OpenRecordset("FoundFiles")
For i = 1 To .FoundFiles.Count
rec.AddNew
rec("FileName") = .FoundFiles(i)
rec.Update
Next i
rec.Close
DoCmd.Close acForm, "FileSearch"
DoCmd.OpenForm "FoundFiles"
Else: MsgBox "No new OpLogs were found in the selected directory!"
End If
End With