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
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
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.