populate a table with files in a folder

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I know I have done this before but I can't remember or find the function. I
need to populate a table with the names of files in a given folder.

Any ideas?

Thanks in advance.

Bonnie
 
Assuming your table is named Files, with a field FileName in it, the
following will put the name of the files into that table:

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

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

If you want the full path to the file, use

strSQL = "INSERT INTO Files (FileName) " & _
"VALUES(" & Chr$(34) & strFolder & strFile & Chr$(34) & ")"
 

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

Back
Top