file list box

G

Guest

Hi. I'm trying to get a list of text files in a certain
directory to show up on my form. I've seen mention of
the "dir$" function but no idea how to use it. In case
it's not apparent, I have no idea what I'm doing. Does
anyone have any
ideas?

Thanks

Tim
 
R

R. Hicks

This should do what you ask ...

Code
-------------------
Private Sub Form_Load()
'
'Add Reference to "Microsoft Scripting Runtime Library"
'
Dim FSO As FileSystemObject
Dim fld As Folder
Dim MyFile As File
Dim strValue As String

Set FSO = New FileSystemObject
Set fld = FSO.GetFolder("C:\Folder\SubFolder")

For Each MyFile In fld.Files
strValue = strValue & MyFile & ";"
Next

strValue = Left(strValue, Len(strValue) - 1)

Me.lstBoxName.RowSourceType = "Value List"
Me.lstBoxName.RowSource = strValue

End Su
 
D

Douglas J. Steele

Just my 2 cents worth, but it's seldom necessary (nor a good idea) to use
FSO.

Anytime you add an external reference, you run the risk of versioning
problems that can cause your entire application to stop working (and FSO has
been known to be prone to versioning problems).

Late binding would be slightly better than setting the reference, but
realistically there's very little that FSO can do that can't be done using
straight VBA or APIs.
 

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