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

Create a FILE search form on network?

Status
Not open for further replies.

Steven547

Technical User
Sep 15, 2004
165
0
0
US
Is it possible to create a form in Access, that searches for files on your network? I would like to create a form that someone can enter a keyword to search for, and it scans the entire network, and displays the paths where these files are found...?

Is this possible in Access and if so how? Or where would I begin?

thanks.
 

I suspect this can be done, and someone here will have an answer that explains how. But, I'm curious. What's the point? You can do exactly that with Windows Explorer which is right in front of you if you're working with an Access database.


Randy
 
I'd like to create a report that displays the paths and where they are located. Then be able to store this info for later use.
 
What's up Steven,
Perhaps this information can lead you in the right direction:

---Posted by Dev Ashish---

------------------------------------------
API: Search for a file
------------------------------------------

(Q) How do I search a hard drive for a file given only it's name and retrieve the path to it??

(A) The first example is applicable only for Access 97. For Access 95, see the alternate method.

You can use the new Office FileSearch object for this. Before using the code, make sure "Microsoft Office 8.0 Object Library" (typically referenced to MSO97.DLL under Office folder) is selected under Tools/References.

Paste the following code in a new module:

'******************** Code Start ************************
'This code was originally written by Dev Ashish.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Dev Ashish

Function fReturnFilePath(strFilename As String, _
strDrive As String) As String

Dim varItm As Variant
Dim strFiles As String
Dim strTmp As String

If InStr(strFilename, ".") = 0 Then
MsgBox "Sorry!! Need the complete name", vbCritical
Exit Function
End If

strFiles = ""
With Application.FileSearch
.NewSearch
.LookIn = strDrive
.SearchSubFolders = True
.FileName = strFilename
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles
If .Execute > 0 Then
For Each varItm In .FoundFiles
strTmp = fGetFileName(varItm)
If strFilename = strTmp Then
fReturnFilePath = varItm
Exit Function
End If
Next varItm
End If
End With
End Function


Private Function fGetFileName(strFullPath) As String
Dim intPos As Integer, intLen As Integer
intLen = Len(strFullPath)
If intLen Then
For intPos = intLen To 1 Step -1
'Find the last \
If Mid$(strFullPath, intPos, 1) = "\" Then
fGetFileName = Mid$(strFullPath, intPos + 1)
Exit Function
End If
Next intPos
End If
End Function
'******************** Code End **************************
Now from your code, call the function as

strFilePath=fReturnFilePath("network.wri","C:")

(Note: Depending on whether you have Microsoft Office's FindFast turned on or not, the search might take a few seconds.)

Alternate: For Access 95 (or for Access 97 also), you can use the following function as a substitute to FileSearch object.


'******************** Code Start **************************
'This code was originally written by Dev Ashish.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
Private Declare Function apiSearchTreeForFile Lib "ImageHlp.dll" Alias _
"SearchTreeForFile" (ByVal lpRoot As String, ByVal lpInPath _
As String, ByVal lpOutPath As String) As Long

Function fSearchFile(ByVal strFilename As String, _
ByVal strSearchPath As String) As String
'Returns the first match found
Dim lpBuffer As String
Dim lngResult As Long
fSearchFile = ""
lpBuffer = String$(1024, 0)
lngResult = apiSearchTreeForFile(strSearchPath, strFilename, lpBuffer)
If lngResult <> 0 Then
If InStr(lpBuffer, vbNullChar) > 0 Then
fSearchFile = Left$(lpBuffer, InStr(lpBuffer, vbNullChar) - 1)
End If
End If
End Function
'******************** Code End **************************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top