I'm trying to fetch items from the Wondows explorer search window and use it in a Access form.
In the first try I fetched the items in a collection and put this collection into at listbox in the form - it kind of worked but some test I did showed tha a listbox has an upper limit around 350-360 items and then the code ran loose like a goose and Access crached - it worked nicely below that limit !
I did a thread on this problem: https://answers.microsoft.com/en-us/msoffice/forum/all/getting-path-filenames-from-explorer-window-to-a/bfa3e196-45aa-4235-9704-2b63b335854f
I now scrapped the collection and the listbox and puts each item from the Windows explorer search window into a table and then shows the records from this table on a form ... still there is a strange limit where Access chrashes ... but below the limit it's working nicely !
Here is my code:
Sub GetSelectedFilesInWinExplorers(sSearchTitle As String, tbl As String) ' As Collection
Dim ExpWin As SHDocVw.ShellWindows 'Object
Dim CurrWin As SHDocVw.InternetExplorer
Dim ExplorerHwnd As Long
Dim i As Long
Set ExpWin = New SHDocVw.ShellWindows
x = 0 ' tæller de fundne emner
For Each CurrWin In ExpWin
If Not CurrWin.Document Is Nothing Then
' I think it's wrong to use ...Title = sSearchTitle to choose the right window because
' when searching for frases the user have to fence the frase ... yeah, with " double qoutationmarks
' but it works for now ...
If CurrWin.Document.folder.Title = sSearchTitle Then
ExplorerHwnd = CurrWin.hwnd
Call ShowWindow(ExplorerHwnd, SW_HIDE) 'Hide the windows since shell isn't hiding it
'-------------------------------------------------------------------------------------------
For i = 0 To CurrWin.Document.folder.Items.Count - 1
If i Mod 3 = 0 Then DoEvents
x = x + 1
strSQL = "INSERT INTO [" & tbl & "] (Nr, KortFilePath) SELECT '" & x & "', '" & _
Mid(CurrWin.Document.folder.Items.Item(CLng(i)).Path, Len(Environ("SlægtHovedmappe")) + 1) & "';"
CurrentDb.Execute strSQL
Next
'--------------------------------------------------------------------------------------------
Exit For
End If
End If
Next CurrWin
If Not CurrWin Is Nothing Then CurrWin.Quit
Set ExpWin = Nothing
End Sub
The For-Next loop between the ------- is the problem !
I cant find the "limit" exactly but when the Windows explorer window holds 180 found files, it's
running nicely ... but 4358 found items the code crashes ... so the limit is somewhere in between.
Why is it a problem at all and how can I work around it ?