Application.FileSearch bug - how to replicate

R

Randy Smith

Try this code to create a bug where the number of names
being returned should only be ONE, but instead, 3 are
returned. Apparently, any name being passed with the
FileName property is treated as though it has a built-in
wildcard.
In Windows 2000, there are 3 files that begin with
catsrv.dll (in Winnt/system32). But, if we try to only
retrieve the first one, all 3 will come back with
FoundFiles.Count.
Dim fs As Object
Set fs = Application.FileSearch
fs.NewSearch
fs.lookin = "C:\winnt\system32"
fs.MatchTextExactly = True
fs.FileName = "catsrv.dll"
If fs.Execute > 0 Then
MsgBox fs.FoundFiles.Count
Else
MsgBox "No files were found"
End If
Even though "catsrv.dll" was passed, in reality 3 files
were retrieved via the Execute method
("catsrv.dll", "catsrvps.dll", and "catsrvut.dll").

DOES anyone know of a workaround?
 
C

Cheryl Fischer

Tested your code in Office XP/Access 2002, and it works correctly returning
only 1 file found.

In a thread dated today in microsoft.public.access.modulesdaovba, Dev Ashish
pointed out that using the File Search Object in Access 97 on Win2K proved
to be a problem. He also indicated that applying SP-2 to Win2K sometimes
solved the problem. You do not indicate what version of Access you are
using, so this is offered as a possibility.

Dev also suggested using the Dir() function, which in your case, as you are
looking for a specific file - not a list of files - might be more
appropriate. Here is how to use it in VBA:

If Len(Dir("C:\WINNT\System32\catsrv.dll", vbDirectory)) > 0 then
MsgBox "Found the file"
else
MsgBox "No file found."
End If

You can also remove the reference to the Microsoft Office xx.x Object
Library, if the only reason you are using it is for FileSearch Object
coding.

hth,
 

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

Similar Threads


Top