By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,463 Members | 774 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,463 IT Pros & Developers. It's quick & easy.

Populate Listbox With FileNames

P: n/a
How can I populate a listbox with a list of the filenames in a certain folder?
Can a query retrieve the filenames from a folder?

Thanks!

Mark
Nov 12 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
You will need to use the DIR function to loop though the folder and add the
filename to a temp table or if there only a few to the source string on the
list box.

"Mark" <mm*****@earthlink.net> wrote in message
news:H9****************@newsread3.news.atl.earthli nk.net...
How can I populate a listbox with a list of the filenames in a certain folder? Can a query retrieve the filenames from a folder?

Thanks!

Mark

Nov 12 '05 #2

P: n/a
See the helpfile for the use of the Dir() function. Have the listbox
RowSourceType set to Value List, use Dir in a loop that builds a string of
the filename like "value1;value2;value3" and then set the Row Source to the
new string.

Mike Storr
www.veraccess.com

"Mark" <mm*****@earthlink.net> wrote in message
news:H9****************@newsread3.news.atl.earthli nk.net...
How can I populate a listbox with a list of the filenames in a certain folder? Can a query retrieve the filenames from a folder?

Thanks!

Mark

Nov 12 '05 #3

P: n/a
"Mark" <mm*****@earthlink.net> wrote in message
news:H9****************@newsread3.news.atl.earthli nk.net...
How can I populate a listbox with a list of the filenames in a certain folder? Can a query retrieve the filenames from a folder?

Thanks!

Mark


A standard way might be to set your listbox ("lstFiles") to be:
Row Source Type = Value List
The code might then be:

Dim strFile As String
Dim strList As String

strFile = Dir("C:\MyStuff\*.*")

While Len(strFile) > 0
strList = strList & strFile & ";"
strFile = Dir()
Wend

Me.lstFiles.RowSource = strList
Fletcher
Nov 12 '05 #4

P: n/a
If you add the list of files to an Access table you can easily bind it to
your control:

How to Add Directory File Names to an Access Table:

Create a table named tblDirectory with 2 fields:
FileName (Text 250)
FileDate (Date/Time)

Call the code below by pressing Ctrl-G to open the debug window and type:
GetFiles("c:\windows\")

Paste this code into a regular module:

Sub GetFiles(strPath As String)
Dim rs As Recordset
Dim strFile As String, strDate As Date

'clear out existing data
CurrentDb.Execute "Delete * From tblDirectory", dbFailOnError

'open a recordset
Set rs = CurrentDb.OpenRecordset("tblDirectory", dbOpenDynaset)

'get the first filename
strFile = Dir(strPath, vbNormal)
'Loop through the balance of files
Do
'check to see if you have a filename
If strFile = "" Then
GoTo ExitHere
End If
strDate = FileDateTime(strPath & strFile)
rs.AddNew
'to save the full path using strPath & strFile
'save only the filename
rs!FileName = strFile
rs!FileDate = strDate
rs.Update

'try for next filename
strFile = Dir()
Loop

ExitHere:
Set rs = Nothing
MsgBox ("Directory list is complete.")
End Sub

--
Joe Fallon
Access MVP

"Mark" <mm*****@earthlink.net> wrote in message
news:H9****************@newsread3.news.atl.earthli nk.net...
How can I populate a listbox with a list of the filenames in a certain folder? Can a query retrieve the filenames from a folder?

Thanks!

Mark

Nov 12 '05 #5

P: n/a
I have a method that is slightly different from the others here. I use a
shell statement to write the entire contents of a directory to a text file,
then import the text file into a table.

On my website (see sig below) is a small sample database called
"DirectoryList.MDB" which illustrates how this is done.

--
--Roger Carlson
www.rogersaccesslibrary.com
Reply to: Roger dot Carlson at Spectrum-Health dot Org

"Mark" <mm*****@earthlink.net> wrote in message
news:H9****************@newsread3.news.atl.earthli nk.net...
How can I populate a listbox with a list of the filenames in a certain folder? Can a query retrieve the filenames from a folder?

Thanks!

Mark

Nov 12 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.