Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / April 2005

Tip: Looking for answers? Try searching our database.

FileSearch - cannot get to work

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Howard Jacobs - 27 Apr 2005 22:03 GMT
I am having trouble with FileSearch:

With Application.FileSearch
   For i = 1 To .SearchFolders.Count
       .SearchFolders.Remove i
       Next i
       
   .NewSearch
   .LookIn = "C:\My Documents"
   .SearchSubFolders = True
   .FileName = "*.*"
   .MatchTextExactly = True
   .FileType = msoFileTypeAllFiles  ' *******************

MsgBox "You are about to search for " & .FileTypes.Count & _
           " file types."

   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

The above code does not compile even though it is copied from "Help" -
msoFileTypeAllFiles is "Variable undefined".

If I omit that line the search returns 0 files.

Pls advise

HJ
John Nurick - 28 Apr 2005 06:42 GMT
>msoFileTypeAllFiles  

This constant is declared in the Microsoft Office X.X Object Library
(X.X being your version number), so the fact that it's not compiling
suggests either that you don't have a reference to the library or that
it's broken.

Go to Tools|References and set a reference to the library.
ALternatively, you could replace msoFileTypeAllFiles with its literal
value, 1.

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
Howard Jacobs - 29 Apr 2005 14:23 GMT
You were right on;  I registered the Object & it compiled OK.

Thank you for your help.

HJ

BTW 2 oddities, I thought:-

1.     .LookIn = "C:\My Documents" doesn't work.  
  I had to use "C:\Documents and Settings\Administrator\My Documents"

2.     I thought that you had to use \\ to get a \ in strings but
"C:\Documents and Settings" & "C:\\Documents and Settings" both work
the same.

>>msoFileTypeAllFiles  
>
[quoted text clipped - 6 lines]
>ALternatively, you could replace msoFileTypeAllFiles with its literal
>value, 1.
John Nurick - 30 Apr 2005 17:02 GMT
>BTW 2 oddities, I thought:-
>
>1.     .LookIn = "C:\My Documents" doesn't work.  
>   I had to use "C:\Documents and Settings\Administrator\My Documents"

This is normal behaviour for Windows. "C:\My Documents" specifies *a*
folder called "My Documents" in the root of the the C: drive, not the
user's actual "My Documents" folder.

In standard English-language installations of Windows you can normally
get the user's My Documents with

 strMyDocsFolder = Environ("USERPROFILE") & "\My Documents"

but I don't think you can be 100% certain that the My Documents folder
is actually called My Documents, or indeed that %USERPROFILE% has not
been tampered with, so it's probably safer to use

 set WshShell = CreateObject("WScript.Shell")
 strMyDocsFolder WshShell.SpecialFolders("MyDocuments")

or the Windows API function SHGetSpecialFolderLocation().

>2.     I thought that you had to use \\ to get a \ in strings but
>"C:\Documents and Settings" & "C:\\Documents and Settings" both work
>the same.

In C-like languages you have to escape a backslash with a backslash, but
not in VBA. (IIRC backslashes in Word fields also need to be doubled.)

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.