PDA

View Full Version : Clear DirListBox()?



belly0fdesir
11-01-2007, 05:10 PM
Hello.

I'm using a modified version of Allen Browne's DirListBox() function (http://allenbrowne.com/func-02.html).

Instead of just referring to a folder location in the code, I'm using criteria supplied by the user on a form. The problem is that the listbox only clears when the database is closed and then re-opened. I would like to add some code either to the beginning of the code I have (which populates the listbox when the user clicks a "Search" button) or add some code to a "Clear List" button.

But I don't know how to clear it without closing and re-opening the database. I've tried several things, but they all just clear and then repopulate with what was there before. And when the user enters different criteria, it just adds it to the list underneath the files that were already listed.

Does this make sense? Does anyone know how I would go about clearing this for a fresh search without closing and re-opening the database?

Please? Thank you :)

XLGibbs
11-03-2007, 08:07 AM
Call the function from your search button code. It will rebuild the list then.

Seems like the function is called now from the On Open. You can invoke the function from your userform.

belly0fdesir
11-05-2007, 10:07 AM
I do have the code attached to my "Search" button event.


Private Sub ICsearchbtn_Click()
Me.ICList.RowSourceType = "ICDirListBox"
End Sub

And it just adds to the end of the list each time, without resetting what was already shown.

This is the code that I'm using to define the function:


Function ICDirListBox(fld As Control, ID, row, col, code)
Dim StrFileName As String
Static StrFiles(0 To 511) As String
Static IntCount As Integer
Select Case code
Case 0
ICDirListBox = True
Case 1
ICDirListBox = Timer
StrFileName = Dir$("\\stxdaicdb04\GSNET\Escrow\iPolicies\ (file://\\stxdaicdb04\GSNET\Escrow\iPolicies\)" & [Forms]![Mainform]![ICyr] & "-" & [Forms]![Mainform]![ICmo] & "\" & [Forms]![Mainform]![ICon] & "*")
Do While Len(StrFileName) > 0
StrFiles(IntCount) = StrFileName
StrFileName = Dir
IntCount = IntCount + 1
Loop
Case 3
ICDirListBox = IntCount
Case 4
ICDirListBox = 1
Case 5
ICDirListBox = 1440
Case 6
ICDirListBox = StrFiles(row)
End Select
End Function

belly0fdesir
11-06-2007, 06:12 PM
If there were some way to empty or reset the static array, that would do it, but I can't seem to figure out a way that will work...

belly0fdesir
11-27-2007, 04:45 PM
Alright... I'm givin' up on this one. Even emailed the author of the code and he said that he isn't going to provide any support on it... meh... I was able to put together something pretty cool, even if the users have to close and open between uses.

I'll just mark it as solved and move on.

Thank you to everyone that helped.