List directory contents to a table

D

Douglas J. Steele

You can use the Dir function to retrieve all of the files in a folder, and
use INSERT INTO statements to load them into a table.

Assuming your table is named FileList, and has a field FileNM, something
like the following untested aircode should work:

Dim strFolder As String
Dim strFile As String
Dim strSQL As String

strFolder = "C:\My Documents"
strFile = Dir(strFolder & "\*.*")
Do While Len(strFile) > 0
strSQL = "INSERT INTO FileList (FileNM) " & _
"VALUES (" & Chr$(34) & strFile & Chr$(34) & ")"
CurrentDb.Execute strSQL, dbFailOnError
strFile = Dir
Loop

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



Broadcasttech.Net said:
Hello
I searched the newsgroup for a way to get a file list of a directory and
send that list to a table but I couldn't find a way. Is there a way to do
this? I found a way to send it to a List Box but that's not what I want.
 
G

Guest

Hell
I searched the newsgroup for a way to get a file list of a directory and send that list to a table but I couldn’t find a way. Is there a way to do this? I found a way to send it to a List Box but that’s not what I want

Any help please would be apprectated
 

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