Solved

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

Posted on 2013-05-18
10
379 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:Ei0914
  • 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:Ei0914
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:Ei0914
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:Ei0914
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:Ei0914
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 500 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:Ei0914
ID: 39195670
Awesome! Thanks for your help!
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

778 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