file list box

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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.
 
Back
Top