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!

Search various folders for a file.

Status
Not open for further replies.

PALman

Technical User
May 15, 2002
160
GB
I have recently been shown how to code a button to find and display any document. I now need to search a number of folders. For example... The documents filenames will always start with a JobNo like 226488 and would be found in the folder named 226000-226500. However to cover any JobNo, I need the search to begin at the folder above this which would be named Completed Jobs. So the file's full path would read "C:\Jobs\Completed Jobs\226000-226500\226488.doc".
Any help again much appreciated.
PALman
 
Thanks JerryKlmns
I have used the LookIn Property of the Application.FileSearch as per listing/posting Aug 14th.
This is within NewSearch which does not work (for me) on its own. It gives a result of sorts which I am trying to get my head round but only after the earlier FileSearch code gives the "My Documents" default. I am getting it to lookin the correct path but I am still not able to open/display the file found. It gives message "Cannot load file".
Also at work the references I referred to above are to version 10 (ie Microsoft Office 10.0 Object Library. But in trying to solve problem at home I am using Version 9.0 of latter. I am getting nearer a solution at work (better results)and so would ask is the version 9.0 a problem?
I list here the entire code as it is tognight...

Private Sub Find_File_Click()
On Error GoTo Err_Find_File_Click

Path = DLookup("[Path]", "[Folder Paths]", "[PathNo] = 'Path02b'")
MsgBox Path

With Application.FileSearch
If .Execute() > 0 Then
.LookIn = Path
MsgBox .LookIn
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

With Application.FileSearch
.NewSearch
.LookIn = Path
.SearchSubFolders = True
'Find filename from ACTIVE JobNo
'In this instance find M-Cert against JobNo in Booking In Log
Dim MCert As String
MCert = DLookup("[M-CertNo]", "Booking In Log", "[JobNo]='" & Forms![QP Status]![JobNo] & "'")
'Filename = MCert
MsgBox Filename
.Filename = MCert
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles
End With
End Sub
Thanks for any further help. I am of on holiday on Sunday for two weeks and will not be able to access Tek-tips so it would be great to put this to bed before then.
Thanks again (to everyone)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top