Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically populate table with filenames in a directory

Status
Not open for further replies.

goldsmt

IS-IT--Management
Jul 30, 2001
53
GB
I want to populate a single column table with all the filenames of a particular extension type in a specific directory and have a button to update the table contents on demand or on a scheduled basis

Regards

Tony
 
this will load the table from downloads with .txt files

Dim MyFolder$, myfile
Dim rst As DAO.Recordset
MyFolder = "C:\downloads\*.txt"
Set rst = CurrentDb.OpenRecordset("Table1")
myfile = Dir(MyFolder)
With rst
While myfile <> ""
.AddNew
.Fields(0) = myfile
.Update
myfile = Dir
Wend
.CLOSE
End With
Set rst = Nothing

would want do
docmd.runsql "delete * from table1

to clear before loading
 
You might want to also insert some code that excludes "." and ".." from the returned values. These values refer to the current and encompassing directories. Including something like:

IF MyFile <> "." And MyFile <> ".." Then

inside the While statement will preclude them from being inserted into your table.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top