Solved

Directory Functions Access VBA

Posted on 2011-09-21
5
346 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
  • 3
  • 2
5 Comments
 
LVL 17

Expert Comment

by:andrewssd3
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
The process worked great. Just needed to add a little more code to my function
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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
User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
Viewers will learn the different options available in the Backstage view in Excel 2013.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now