Loadinf listbox with files in a directory

G

Guest

I have folled the instructions in Allen Browne's website (see code below) -
http://allenbrowne.com/func-02.html.

But the problem that I am having is taht when I attach the function to the
listbox ,it runs okay the first time,But when the form is loaded again it
duplicates the contents of the directory again ,thus showing repeating values
to the end user.

Can anyone,please, help out of this malaise.



sysAccountant




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.
' Notes: You could read a FileSpec from an underlying form.
' Error handling not shown. More than 512 files not handled.
Dim StrFileName As String
Static StrFiles(0 To 511) As String ' Array to hold File Names
Static IntCount As Integer ' Number of Files in list

Select Case code
Case 0 ' Initialize
DirListBox = True

Case 1 ' Open: load file names into array
DirListBox = Timer
StrFileName = Dir$("C:\") ' Read filespec from a form here???
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


===================================================
 
G

Guest

I don't know for sure, but I think you just need to change this
Case 0 ' Initialize
DirListBox = True

to this

Case 0 ' Initialize
IntCount = 0
DirListBox = True
 
G

Guest

John

Thanks

It works!


Regards

sysAccountant

John Nurick said:
I don't know for sure, but I think you just need to change this


to this

Case 0 ' Initialize
IntCount = 0
DirListBox = True
 

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