Solved

Directory Functions Access VBA

Posted on 2011-09-21
5
351 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
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

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…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

770 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