Results 1 to 3 of 3
  1. #1
    joflow21 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Oct 2013
    Posts
    13

    Importing most current csv file within a folder

    I need to figure out how to write a code that will import the most current csv file within a specified folder. What I have now is...



    Code:
    DoCmd.TransferText acImportDelim, "1", "LFGLoanRpt", "J:\Processing\Documentation\Reporting\LNL\MarksLoanReport\MarksLoanReport_01-03-2014.csv", False, "", 437
    Every business day, a new file is added. How do I have it import the most current file?

    Thanks,
    Joflow

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    you'll probably have to find the most recent file by one of two methods

    1. if your file names are always the same format you can take the previous day's date (or the current days' date) and look for a file with that name
    or
    2. use filesystemobject commands to cycle through files in a folder and find the most recent one by datemodified or datecreated

    I prefer the latter

    here's a link to an example of cycling through files in a specific folder:

    http://blogs.technet.com/b/heyscript...ubfolders.aspx

    here's a list of the properties you can access with the filesystemobject commands:

    http://msdn.microsoft.com/en-us/libr...=vs.84%29.aspx

    you most likely want one of these

    DateCreated
    DateLastAccessed
    DateLastModified

    you can cycle through the files using a simple date check to find the most recent then once you've processed all the files use the file with the most recent relevant date

  3. #3
    joflow21 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Oct 2013
    Posts
    13
    Thank you rpeare. I apologize for taking so long to respond. It has been a rough year so far.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. How to copy a file from one folder to another in vba
    By pkstormy in forum Code Repository
    Replies: 2
    Last Post: 09-20-2012, 05:32 PM
  2. Replies: 21
    Last Post: 08-20-2012, 11:59 PM
  3. Replies: 2
    Last Post: 05-25-2012, 07:36 AM
  4. Replies: 21
    Last Post: 01-24-2012, 06:21 PM
  5. Importing picture from folder
    By Thejas.s in forum Import/Export Data
    Replies: 0
    Last Post: 04-06-2011, 09:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums