ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   populate listbox as textbox changes question (https://www.excelbanter.com/excel-programming/393362-populate-listbox-textbox-changes-question.html)

Gary Keramidas

populate listbox as textbox changes question
 
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



--


Gary





Gary Keramidas

populate listbox as textbox changes question
 
forget it, i changed this line and it seems to be working.

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

--


Gary


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
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



--


Gary








All times are GMT +1. The time now is 01:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com