Results 1 to 6 of 6
  1. #1
    mchadwick is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Posts
    71

    Importing any file in a folder

    I have a CSV I am putting in a folder on my hard drive. lets say "C:\folder". I would like Access when I run a macro to go out and get the file that is in that folder and import it into the a table in the DB. The file name is never going to be the same name, there are a great deal of files and I need the file name to stay what it is.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    Pointing to the folder is easy. How should Access know which file to import? Is it the only file in the folder?

    It is possible to have code do a "For Each File in Folder" procedure. If there is only the one file then it will simply act on that one file.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    mchadwick is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Posts
    71
    There are going to be 236 files in there at one time and they all need to be imported. I would love to have something do it all at one time, but my delima is that the file name needs to be added to one of the columns on each record in that file to be imported. I need to know where the record came from. They all go into the same table though and all get processed the same way. They are all basically the same file, with different data.

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Here's what I would do:

    1. use file systemobject commands to retreive file names from the folder in question (http://www.4guysfromrolla.com/webtec...ect/faq5.shtml)
    2. update the 'permanent' table's default value for the 'source' file (make it the last column it will make things easier on you) using alter table or some other method (http://stackoverflow.com/questions/1...e-syntax-error)
    3. Use your transfer method (docmd.transferspreadsheet) to append the data to the 'permanent' table.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    Think want to reverse steps 3 and 2 and use UPDATE sql to populate the 'source' field.

    This assumes the spreadsheets have a simple structure that DoCmd.Transferspreadsheet can work with.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    assuming there is no default value to start the default value has to be changed on the import of the first file, and you are absolutely right, this assumes every file has exactly the same structure. If they don't you'll have to get more creative.

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

Similar Threads

  1. Importing most current csv file within a folder
    By joflow21 in forum Import/Export Data
    Replies: 2
    Last Post: 04-11-2014, 11:35 AM
  2. Replies: 3
    Last Post: 02-05-2014, 04:25 AM
  3. Replies: 21
    Last Post: 08-20-2012, 11:59 PM
  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

Tags for this Thread

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