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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filesearch Object in XP 1

Status
Not open for further replies.

BusMgr

IS-IT--Management
Aug 21, 2001
138
US
I have code behind a cmd button on my swichboard to find and run an external application. It works fine with Access 2K, but when I move the application to XP, it consistently returns 'No file found'. I even cut and pasted the VBA help example, and it returns file not found.

Any help would be appreciated.

My code as follows:

'Perform simple search using the FileSearch object.

Dim varItem As Variant

With Application.FileSearch
.NewSearch
.Filename = "HYD.exe"
.LookIn = "C:\"
.SearchSubFolders = True
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles
.Execute

'Part II
If .Execute() > 0 Then
'MsgBox "There were " _
.FoundFiles.Count & _
" file(s) found."

'MsgBox .FoundFiles(1)
varItem = .FoundFiles(1)
Call Shell(varItem, 1)

Else

MsgBox "There were no files found."

End If

End With
thanks
BusMgr
 
Hi there,

I have AccessXP and pasted your code - it worked fine. Although I did need to set a reference to "Microsoft Office 10.0 Object Library".

[tt]
Public Function FindMeFile()
Dim varItem As Variant

With Application.FileSearch
.NewSearch
.Filename = "HYD.exe"
.LookIn = "C:\"
.SearchSubFolders = True
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles
'.Execute This is not needed, because of next line of code

'Part II
If .Execute() > 0 Then
MsgBox "There were " & _
.FoundFiles.Count & _
" file(s) found."

'MsgBox .FoundFiles(1)
varItem = .FoundFiles(1)
Call Shell(varItem, 1)

Else

MsgBox "There were no files found."

End If

End With

End Function
[tt]
 
I have been having the same problem with Filesearch. I pasted the code from the previous reply into my Access data base and it does not work for me. I also have AccessXP.
 
I don't have the same PC that I was having the initial problem on available. I created a new db on an XP machine, cut and pasted the code, made sure the Reference was set to "MS Office 10.0 Object Library" and ran the program. It did not recognize the ".FileType = msoFileTypeAllFiles", line of code, but after remarking that out, it ran and found the file.

I did not take the time to set it up as function, I just put an On Click [Event Procedure] and ran it as a Private Sub. I do not think that would make a difference.

??Why the .FileType = msoFileTypeAllFiles does not work?

I will try it again when I get back the original PC that I was having trouble with.

Thanks
BusMgr
 
It makes sense to have a reference to "Microsoft Office xx.x Library" since FileSearh is part of the Shared Office Components, but I have know idea why the .FileType Enum is not working for you. The .FileSearch property did not work for me either until I set the reference. However, once the reference was set, i had no problems.

The default Enum for .FileType in Office XP is msoFileTypeOfficeFile. So, i'm even more purplexed how the code worked (ie could find the file) when you 'commented out' the .FileSearch property, since you're not searching for an office file.

I did find this link:

but i'm not sure if its of any value to you (its long).

Cheers,
Dan
 
There is a great example on the Microsoft Visual Basic Help Line if you lookup FileDialog Object. Their example is pretty simple code for something so incredibly hard to find. For some reason it took numerous 'searches' at MS Online to even find help for 'FileDialog'. I couldn't get it to work on my machine and noticed DanJR's message about the reference. I added reference 11.0 and it worked perfectly.

Thanks,
Brooks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top