callback function for filenames into listbox

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
 
S

Stuart McCall

----- Original Message -----
From: "Chad" <[email protected]>
Newsgroups: microsoft.public.access.formscoding
Sent: Thursday, August 14, 2008 11:42 PM
Subject: callback function for filenames into listbox

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

Insert the following line in the case 1 block, just before the DirListBox =
Timer line:

Erase StrFiles
 
C

Chad

Stuart McCall said:
----- Original Message -----
From: "Chad" <[email protected]>
Newsgroups: microsoft.public.access.formscoding
Sent: Thursday, August 14, 2008 11:42 PM
Subject: callback function for filenames into listbox



Insert the following line in the case 1 block, just before the DirListBox =
Timer line:

Erase StrFiles



Now when the form opens the list box is blank. Not sure why
 
S

Stuart McCall

Ok, try putting it in the case 0 block.

(I can never remember which is right)
 

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