How to execute free text search in linked documents?

Sima

New member
Local time
Today, 07:52
Joined
Apr 10, 2014
Messages
3
Hi all,
I have a table which lists all documents that refer to a certain entity. the table contains the file names and paths.
I would like the user to be able to search for text inside these documents.
Can I use Windows Search for that by using code? Is there any other way?

Thanks,
Sima
 
One way is using FileSystemObject

Open the file in memory using FSO and read it line by line to EOF.

Can be tricky with some scenarios as sometimes it may throw an EOF by error if the file has not finished loading.
You may have to put in a error handler to make sure the file actually loads before you start the code to reading it.
 
I agree with the approach suggested by BBE. How often do you have to do such a search?
Can you tell us more details about the number of files, the number of words, the frequency of searching--- the purpose of this. There may be more options.
 
Here is a very basic example:
Code:
Sub UseFSO(CurrFile As String, LookingFor As String)
Dim CurrFSO As New FileSystemObject
Dim CurrLine As String

Set CurrFSO = CurrFSO.OpenTextFile(CurrFile)

Do While CurrFSO.AtEndOfStream = True
    AtttemptCounter = AtttemptCounter + 1
Loop

Do Until CurrFSO.AtEndOfStream
    CurrLine = CurrFSO.ReadLine
    If InStr(1, CurrLine, LookingFor) > 0 Then
        MsgBox LookingFor & " has been found!"
        Exit Sub
    End If
Loop
MsgBox LookingFor & " was not found"

End Sub

Where "CurrFile" = fully resolved path with file name
Where "LookingFor" = the text you're searching for in the document
 
I agree with the approach suggested by BBE. How often do you have to do such a search?
Can you tell us more details about the number of files, the number of words, the frequency of searching--- the purpose of this. There may be more options.

Thanks, JDRAW.
I have an application which manages projects including their related documents (hundreds) - word files, excel files. etc. There is a great need for finding specific documents frequently by certain parameters and by text inside the documents content. Searching by parameters is easy but searching throgh the content in the files - I have no Idea how to do this from within the Access application.

Sima
 
Here is a very basic example:
Code:
Sub UseFSO(CurrFile As String, LookingFor As String)
Dim CurrFSO As New FileSystemObject
Dim CurrLine As String

Set CurrFSO = CurrFSO.OpenTextFile(CurrFile)

Do While CurrFSO.AtEndOfStream = True
    AtttemptCounter = AtttemptCounter + 1
Loop

Do Until CurrFSO.AtEndOfStream
    CurrLine = CurrFSO.ReadLine
    If InStr(1, CurrLine, LookingFor) > 0 Then
        MsgBox LookingFor & " has been found!"
        Exit Sub
    End If
Loop
MsgBox LookingFor & " was not found"

End Sub

Where "CurrFile" = fully resolved path with file name
Where "LookingFor" = the text you're searching for in the document

Thank a lot, I'll try this tomorrow and let you know!
 

Users who are viewing this thread

Back
Top Bottom