Filesearch

N

NIC

Has anyone ran into this before...

I can't seam to get Filesearch to find any files

The below code consistantly returns .Execute = 0 (no files
found)

Any ideas or help is greately appreciated

Sub GetFileList()
Dim strDirName As String: strDirName = CurDir()
Dim strPrompt As String: strPrompt = strDirName & Chr(13)
Dim i As Long
With Application.FileSearch
.NewSearch
.LookIn = "C:\My Documents"
.SearchSubFolders = False
.FileName = "*.*"
.Execute
If .FoundFiles.Count > 0 Then
For i = 1 To .FoundFiles.Count
strPrompt = strPrompt & .FoundFiles(i) & Chr(13)
Next i
Else
strPrompt = strPrompt & "No files found."
End If
MsgBox strPrompt
End With
End Sub
 
N

NIC

-----Original Message-----


That code works fine for me. I do note that you're hard- coding "C:\My
Documents" instead of using the variable strCurDir; is that an
oversight?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.
--------------------------------------------------------
Just an oversite, however, regardless of what drive,
folder, filename I use, filesearch still returns 0 files
in all my VBA code.

I use office10 (XP, 2002), my MSO.DLL is dated 6/22/2002.
Any idea if this is correct? I haven't found anything on
Knowledgebase...
 
N

NIC

The file reports version 10.0.4219.0

I've even uninstalled/reinstalled office to try and fix
this but it didn't work...
 
N

NIC

Dirk,

Found a post on another newsgroup that suggested turning
off Indexing Services. IT WORKED! FileSearch now
functions correctly.

Have you heard of such?
 
D

Dirk Goldgar

NIC said:
Dirk,

Found a post on another newsgroup that suggested turning
off Indexing Services. IT WORKED! FileSearch now
functions correctly.

Have you heard of such?

I never had before, but a little Googling reveals several messages
associating this problem with the Indexing Service. Even aside from
this issue, I've seen enough messages involving quirks in the FileSearch
object that I've always steered clear of it. If I wanted to do what you
were doing -- get a list of all the files in a folder -- I'd just use
the Dir function in a loop, like the following air code:

Sub GetFileList()

Dim strDirName As String
Dim strPrompt As String
Dim strFileName As String
Dim lngCount As Long

strDirName = CurDir()

strFileName = Dir(strDirName & "\*.*")

Do Until Len(strFileName) = 0
lngCount = lngCount + 1
strPrompt = strPrompt & Chr(13) & strFileName
strFileName = Dir()
Loop

If lngCount > 0 Then
strPrompt = strDirName & strPrompt
Else
strPrompt = strDirName & Chr(13) & "No files found."
End If

MsgBox strPrompt

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top