Fill Listbox

B

Billy Banter

Hello all,
I want a list box that has all the names of files located in a directory. Is
this possible?

eg C:\Documents and Settings\Administrator\My Documents\*.jpg

Regards
Richard
 
P

Peter Doering

I want a list box that has all the names of files located in a directory. Is
this possible?

eg C:\Documents and Settings\Administrator\My Documents\*.jpg

Modified example from OH, "Dir Function Example":

MyPath = "C:\Documents and Settings\Administrator\My Documents\*.jpg"
MyName = Dir(MyPath) ' first entry.
Do While MyName <> ""
MyRowSource = MyRowSource & ";" & MyName
End If
MyName = Dir ' Get next entry.
Loop
Me!MyListBox.RowSource = Mid(MyRowSource,2)

(not tested)

HTH - Peter
 
B

Billy Banter

Figured this one out now.

Private Sub Command13_Click()

Dim myfiles As Object
Dim i As Integer
Dim strHold As String

Set myfiles = Application.FileSearch
With myfiles
.LookIn = "C:\files\"
.FileName = "*.jpg"
If .Execute > 0 Then
MsgBox .foundfiles.Count & " file(s) found."
For i = 1 To .foundfiles.Count
strHold = strHold & ";" & .foundfiles(i)
Next i
Else
MsgBox "No files found."
End If
End With
strHold = Mid(strHold, 2)
DirListBox.RowSource = strHold
End Sub
 
L

Larry Linson

A list box is for allowing the user to select one or multiple items in the
list. If that is what you are doing, you may find it simpler to use the
code, donated by Ken Getz, that allows you to let the user choose or enter a
file with the Windows Common Dialog (an interface with which they are
probably already familiar).

You'll find it at http://www.mvps.org/access/api/api0001.htm.

Larry Linson
Microsoft Access MVP
 

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