Solved

Directory Functions Access VBA

Posted on 2011-09-21
5
355 Views
Last Modified: 2012-05-12
I am trying to find a functions in Micorosoft access 2007(vba) that imports a directory structure  into a microsoft access table.   I can get the filename to be inserted into the table.  But I would like to have the Date modified field also added to the table.
GetFiles.txt
0
Comment
Question by:centralmike
[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
  • 3
  • 2
5 Comments
 
LVL 17

Expert Comment

by:andrewssd3
ID: 36574398
I'm puzzled - you have attached a text file that does what you are asking - it works for me if iI run it in Access in a database that has a table tblDirectory, with columns FileName and FileDate - have you got the columns defined in the table?
0
 
LVL 17

Expert Comment

by:andrewssd3
ID: 36574425
The way it is coded, you need to include the filal backslash at the end of the path, or it returns nothing, so something like
Call GetFiles("c:\documents and settings\user\desktop")

Open in new window

0
 

Accepted Solution

by:
centralmike earned 0 total points
ID: 36574548
Hi Andrew, In windows explore we have the four columns.
FileName Size Type Date Modified.  The program imports the FileName column but I would like to import the Date Modified column also through VBA code.  The date your seeing in the text file is just the current date.
0
 
LVL 17

Expert Comment

by:andrewssd3
ID: 36574661
No - it uses the FileDateTime function which according to the documentation contains the date when the file was created or last modified.  I'll paste the code here slightly tidied up:

Sub GetFiles(strPath As String)

    Dim rs As Recordset
    Dim strFile As String
    Dim dtDate As Date
    
    'clear out existing data
    CurrentDb.Execute "Delete * From tblDirectory", dbFailOnError
    
    'open a recordset
    Set rs = CurrentDb.OpenRecordset("tblDirectory", dbOpenDynaset)
    
    'get the first filename
    strFile = Dir(strPath, vbNormal)
    'Loop through the balance of files
    Do While strFile <> ""
        
        dtDate = FileDateTime(strPath & strFile)
        rs.AddNew
        'to save the full path using strPath & strFile
        'save only the filename
        rs!FileName = strFile
        rs!FileDate = dtDate
        rs.Update
        
        'try for next filename
        strFile = Dir()
        
    Loop
    
    Set rs = Nothing
    MsgBox ("Directory list is complete.")

End Sub

Open in new window

0
 

Author Closing Comment

by:centralmike
ID: 36908494
The process worked great. Just needed to add a little more code to my function
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

The canonical version of this article is on my web site here: http://iconoun.com/articles/collisions/ A companion presentation is available here: http://iconoun.com/articles/collisions/Unicode_Presentation.pdf
As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

707 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