Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using windows explorer search files or folders

Status
Not open for further replies.

leckie

Programmer
Apr 19, 2001
65
GB
Does anyone know if one can utilise the "search files containing text" of windows explorer from within access ?

regards Leckie
 
Hi,

Have a read of the help system for the "File Search" object. There is a MatchAllWordForms property and a good example of how to use the property.

Cheers,
Mark.
 
Hi Mark,

I found the code for matchallwordforms i.e.

With Application.FileSearch
.NewSearch
.LookIn = "C:\My Documents"
.SearchSubFolders = True
.TextOrProperty = "run"
.MatchAllWordForms = True
.FileType = msoFileTypeAllFiles
End With

thankyou but...


it falls over on .FileType = msoFileTypeAllFiles

variable not defined

any clues ?

regards
Leckie

 
Hi Leckie,

Yes your correct. I can't compile using the msoFileType constants either.

Delete that line and add a .fileName property as follows:

With Application.FileSearch
.NewSearch
.LookIn = "C:\My Documents"
.SearchSubFolders = True
.FileName = "*.txt"
.TextOrProperty = "run"
.MatchAllWordForms = True
'.FileType = msoFileTypeAllFiles
End With

Hopefully this will give you what your after.

Cheers,
Mark.
 
Hi Mark,

managed to get the code work except It will only work with *.doc file types, any clues ?

regards Leckie

Dim fs As Object
Dim I As Integer

Set fs = Application.FileSearch
With fs
.NewSearch
.LookIn = "C:\My Documents"
.SearchSubFolders = True
.TextOrProperty = "the"
.MatchAllWordForms = True
'.FileName = "*.txt"
If .Execute > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For I = 1 To .FoundFiles.Count
MsgBox .FoundFiles(I)
Next I
Else
MsgBox "There were no files found."
End If
End With
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top