C
Chad
I have the following code in my database to go out into a directory and pull
back filenames matching the criteria. My question is, every time the form is
loaded it just adds on to the list. I want it to clear out the list and
repopulate. The way its working now I have duplicates added every time the
form is reloaded. Any help is greatly appreciated!
Function DirListBox(fld As Control, ID, row, col, code)
' Purpose: To read the contents of a directory into a ListBox.
' Usage: Create a ListBox. Set its RowSourceType to "DirListBox"
' Parameters: The arguments are provided by Access itself.
Dim strGlobalPath As String
Dim strExtension As String
Dim StrFileName As String
Static StrFiles(0 To 25) As String ' Array to hold File Names
Static Intcount As Integer ' Number of Files in list
strGlobalPath = "xxxx"
strExtension = "\xxx*.xls"
Select Case code
Case 0 ' Initialize
DirListBox = True
Case 1 ' Open: load file names into array
DirListBox = Timer
StrFileName = Dir(strGlobalPath & strExtension)
Do While Len(StrFileName) > 0
StrFiles(Intcount) = StrFileName
StrFileName = Dir
Intcount = Intcount + 1
Loop
Case 3 ' Rows
DirListBox = Intcount
Case 4 ' Columns
DirListBox = 1
Case 5 ' Column width in twips
DirListBox = 1440
Case 6 ' Supply data
DirListBox = StrFiles(row)
End Select
End Function
back filenames matching the criteria. My question is, every time the form is
loaded it just adds on to the list. I want it to clear out the list and
repopulate. The way its working now I have duplicates added every time the
form is reloaded. Any help is greatly appreciated!
Function DirListBox(fld As Control, ID, row, col, code)
' Purpose: To read the contents of a directory into a ListBox.
' Usage: Create a ListBox. Set its RowSourceType to "DirListBox"
' Parameters: The arguments are provided by Access itself.
Dim strGlobalPath As String
Dim strExtension As String
Dim StrFileName As String
Static StrFiles(0 To 25) As String ' Array to hold File Names
Static Intcount As Integer ' Number of Files in list
strGlobalPath = "xxxx"
strExtension = "\xxx*.xls"
Select Case code
Case 0 ' Initialize
DirListBox = True
Case 1 ' Open: load file names into array
DirListBox = Timer
StrFileName = Dir(strGlobalPath & strExtension)
Do While Len(StrFileName) > 0
StrFiles(Intcount) = StrFileName
StrFileName = Dir
Intcount = Intcount + 1
Loop
Case 3 ' Rows
DirListBox = Intcount
Case 4 ' Columns
DirListBox = 1
Case 5 ' Column width in twips
DirListBox = 1440
Case 6 ' Supply data
DirListBox = StrFiles(row)
End Select
End Function