populate listbox as textbox changes question

G

Gary Keramidas

i use the first code snippet to populate a userform listbox as the user types in
a filename into a
textbox. so, it a user starts to type "test", it will filter the filenames that
start with "test".

so i tried the 2nd code snippet, but it is very slow to react to the textbox
input
is there another way that would perform better as the user types "test" into a
textbox,
so the listbox is populated with "testing.xls" and "this is a test.xls"?


Me.ListBox1.Clear
fname = Dir(fPath & "\" & Me.tbCode & "*.xls")

Do While fname <> ""
Me.ListBox1.AddItem StrConv(Left(fname, Len(fname) - 4),
vbProperCase)
fname = Dir()
Loop

'2nd code

Set fs = Application.FileSearch
With fs
.LookIn = fPath
.SearchSubFolders = False
.Filename = "*" & Me.tbCode & "*.xls"
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Me.ListBox1.AddItem Right(.FoundFiles(i),
Len(.FoundFiles(i)) - InStrRev(.FoundFiles(i), "\"))
Next i
Else

End If
End With
 
G

Gary Keramidas

forget it, i changed this line and it seems to be working.

fname = Dir(fPath & "\*" & Me.tbCode & "*.xls")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top