L
lcannon
Guest
I need help to modify this function to be able to search all text files in a folder under c:\files and get the file names of the files that has matches to the strings in Field 2 of tblsearch and add those filenames to a table tblfiles. In other words I need to search all text files for strings matching any of the strings in field2 and place those filenames that have matching strings into a table.
Function GetFilename(strDrive As String)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
DoCmd.SetWarnings False
DoCmd.SetWarnings True
Set rs = db.OpenRecordset("tblfiles")
' resume next, on some items, read permissions are not allowed...
On Error Resume Next
Dim FileNameFound As String, i As Integer
With Application.FileSearch
.FileName = "*.txt"
.SearchSubFolders = True
.LookIn = strDrive & "\"
.Execute
If .FoundFiles.Count >= 1 Then
For i = 1 To .FoundFiles.Count
rs.AddNew
rs!Location = .FoundFiles(i)
rs.Update
Next
End If
End With
rs.Close
Set db = Nothing
End Function
Function GetFilename(strDrive As String)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
DoCmd.SetWarnings False
DoCmd.SetWarnings True
Set rs = db.OpenRecordset("tblfiles")
' resume next, on some items, read permissions are not allowed...
On Error Resume Next
Dim FileNameFound As String, i As Integer
With Application.FileSearch
.FileName = "*.txt"
.SearchSubFolders = True
.LookIn = strDrive & "\"
.Execute
If .FoundFiles.Count >= 1 Then
For i = 1 To .FoundFiles.Count
rs.AddNew
rs!Location = .FoundFiles(i)
rs.Update
Next
End If
End With
rs.Close
Set db = Nothing
End Function