Solved

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

Posted on 2013-05-18
10
382 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
[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
  • 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

756 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