Solved

Populate Access Table with names of documents in a folder

Posted on 2011-09-08
6
255 Views
Last Modified: 2012-05-12
I have written Access VBA Code that opens a folder and displays all the documents in that folder.

QUESTION:

How do I use the FileSystemObject to populate a table with the document names?

I would greatly appreciate some help

Biggles1
0
Comment
Question by:Biggles1
6 Comments
 
LVL 12

Assisted Solution

by:danishani
danishani earned 100 total points
ID: 36503477
Check this nice Function out of Allen Browne:
http://www.everythingaccess.com/tutorials.asp?ID=List-files-to-a-table

Hope this helps,
Daniel
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 400 total points
ID: 36503484


Sub gFiles()

Dim initPath As String, strFile As String
Dim objFSO, objFdr
   initPath = "C:\ Folder1\Folder2\"
   Set objFSO = CreateObject("Scripting.FileSystemObject")
   Set objFdr = objFSO.GetFolder(initPath)
        strFile = Dir(initPath & "\*.*")
        Do Until strFile = ""
           
            'your code to add the filenames to the table

            strFile = Dir
        Loop

End Sub
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 36503532
capricorn1,

Have not use the FSO for a couple of years, but when I did, I generally found that it was quite a bit slower than just using DIR() to loop through the various folders and files.  Do you know if this is still the case?
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 119

Expert Comment

by:Rey Obrero
ID: 36503569

@fyed- yes, i think that is one of the reason why i use Dir() in my recursive search code.
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 36503581
the link that danishani posted above http:#a36503477 have the recursive search codes
0
 
LVL 26

Expert Comment

by:Nick67
ID: 36504294
It'd help if you posted the code you have already.
I assume you have a FileDialog object on the go.
<opens a folder and displays all the documents in that folder>
And I suspect that the .Show is opening Windows Explorer window.

It's not that hard to take the vrtSelectedItem from that, and then do a GetFolder, GetFiles, and loop once through the Files collection, writing records to a table

The structure and name of the table would be nice to know too because the loop will be something like

dim rs as recordset
set rs = currentdb.openrecordset("select * from SomeTable where 1=2;",dbopendynaset)
for each myFile in myFiles
    with rs
       .addnew
       !PathName = vrtItemSelected
       !FileName = myfile.name
       .update
    end with
loop

But I can't do the syntax up without REALLY knowing what you have on the go.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now