Solved

Directory Functions Access VBA

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

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

Suggested Solutions

Title # Comments Views Activity
Microsoft Access Table name 3 71
C# LINQ ForEach() question 6 113
SharePoint 2013 Site Replacement 6 71
Windows 10, Hotmail and AdChoices 7 63
MS Access 2003 or later To MySQL Migration Project Hello All, this is my second article in the category of MS-OFFICE Automation. In internet I am not able to find any comprehensive resource on the Migration of MS Access back-end to MySQL so I fin…
This collection of functions covers all the normal rounding methods of just about any numeric value.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

732 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