PDA

View Full Version : Get result from a search in explorer into a Access listbox ?



ksor
02-12-2020, 12:50 PM
I have made a test form with at textbox for my search criteria AND a button to execute the search - simple and easy, and it shows me a explorer window with the search results.

Try yourself with this simple code behind the button:


Dim WhatToSearchFor As String
Dim WhereToSearch As String
WhatToSearchFor = Chr(34) & txtSearchFor.Value & Chr(34)
WhereToSearch = Environ("SlægtHovedmappe")
Shell "explorer.exe " & Chr(34) & "search-ms:query=" & WhatToSearchFor & "&crumb=location:" & WhereToSearch & Chr(34), vbNormalFocus



It you want to search for FRASES (in my danish version) you HAVE to use double qoutation marks around the frase, like this: "I look for this frase in my documents"

The search is very, VERY fast and it looks into doc, docx, PDF, msg ... you name it, in all subfolders - I think it's a very powerfull method !

BUT ...

I need to get the search result BACK to the Access form in a listbox ... BUT HOW ?

OBP
02-13-2020, 02:37 AM
Have you tried setting the search to a string?

ksor
02-13-2020, 04:51 AM
???
I don't get you ... please explain - I don't think this is the answer to my Q :crying:

OBP
02-13-2020, 07:22 AM
Try something like
Dim result as string

result = Shell "explorer.exe " & Chr(34) & "search-ms:query=" & WhatToSearchFor & "&crumb=location:" & WhereToSearch & Chr(34), vbNormalFocus

msgbox result.

ksor
02-13-2020, 07:39 AM
??? it just returns the number 6844 ... right now, it tells me nothing :banghead:

OBP
02-13-2020, 08:39 AM
Your code just opens a new version of Explorer Search.
What do you actually want the List box to contain?
Can you provide a mock example?

If you just want a list of File names I can supply VBA code that uses DIR to do so.

ksor
02-13-2020, 09:23 AM
I want to search through 1000's of Word documents in 10's of subfolders and show the file names for those containing a specific word or FRASE.

The Shell-method can do it very, very fast compared to some VBA coded sub and we are talking 100-500 times faster !

BUT ...

I want to be able to define the search criteria (the word or the frase) in textbox on a Access form (that I can do now !)

AND

I want to see the result in a listbox on that same form.

The reason ... I want to present different infos for the user when he's double clicking on the files.
Depending on what subfolder the files is stored in, the file is related to a specific info in other parts of the whole system.

But what's the problem now is to get the result into the listbox on that form :crying:

Hope you understand what I mean.

OBP
02-14-2020, 01:57 AM
I know what you want it to do, but I have googled it and can't find any information on using VBA to do it at all.
You can copy and paste the data but that is no help.
Sorry I couldn't help.