Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBA Code to populate a table with a list of FOLDERS in a specified drive

Posted on 2013-05-18
10
Medium Priority
?
390 Views
Last Modified: 2013-05-24
Hello Experts.

I have the code to populate a table with the files in a specified location but can't seem to get the FOLDER NAMES and store the results in a table.

Any help would be appreciated.

Thanks!!
0
Comment
Question by:Eileen Murphy
  • 5
  • 5
10 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39177723
<I have the code to populate a table with the files in a specified location>

post the codes you are using...


or see this link

http://allenbrowne.com/ser-59.html
0
 

Author Comment

by:Eileen Murphy
ID: 39177730
That's the code I use to get the filenames in a specified folder -- works great! I now want to get the folder names and can't get it to work...
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39177744
ok.. in this part of the code


 'Add the files to the folder.
    strFolder = TrailingSlash(strFolder)
    strTemp = Dir(strFolder & strFileSpec)
    Do While strTemp <> vbNullString
         gCount = gCount + 1
         SysCmd acSysCmdSetStatus, gCount
        strSQL = "INSERT INTO Files " _
          & " (FName, FPath) " _
          & " SELECT """ & strTemp & """" _
          & ", """ & strFolder & """;"

         CurrentDb.Execute strSQL
        colDirList.Add strFolder & strTemp
        strTemp = Dir
    Loop


' strFolder is the string that holds the complete folder path

and the code is storing it in the field FPath..
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

Author Comment

by:Eileen Murphy
ID: 39177755
When I run the code it returns the path ONLY for files found in the folder.... what I want is to populate the table with all the folders within a specific folder or network path or whatever.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39177761
are you using the exact code i posted?
0
 

Author Comment

by:Eileen Murphy
ID: 39177797
I am. When I run it against a folder with 58 subfolders and 8 files I get 8 records in my table.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39177805
I get 8 records in my table with the folder path ? is this correct

and are you expecting to get all the 58 subfolders , 50 of which does not have file on them ?
0
 

Author Comment

by:Eileen Murphy
ID: 39177856
Right -- I want to populate a table with the directory structure (folder names) basically.. they represent their client list as each folder is unique to their customers...
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 39177863
try this revision of the codes above


    strFolder = TrailingSlash(strFolder)
    strTemp = Dir(strFolder & strFileSpec)
    Do While strTemp <> vbNullString
      
            if strTemp & ""="" then
                  strSQL = "INSERT INTO Files " _
                    & " (FName, FPath) " _
                    & " SELECT """ & strTemp & """" _
                    & ", """ & strFolder & """;"
                   CurrentDb.Execute strSQL
              end if
      
      
      
         gCount = gCount + 1
         SysCmd acSysCmdSetStatus, gCount
        strSQL = "INSERT INTO Files " _
          & " (FName, FPath) " _
          & " SELECT """ & strTemp & """" _
          & ", """ & strFolder & """;"
         CurrentDb.Execute strSQL
        colDirList.Add strFolder & strTemp
        strTemp = Dir
    Loop
0
 

Author Closing Comment

by:Eileen Murphy
ID: 39195670
Awesome! Thanks for your help!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

772 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