Solved

Populate Access Table with names of documents in a folder

Posted on 2011-09-08
6
263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36503569

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

Expert Comment

by:Rey Obrero (Capricorn1)
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

738 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