Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Import all CSV files in folder using Access 2010

Posted on 2015-01-22
7
Medium Priority
?
611 Views
Last Modified: 2015-01-23
I'm trying to import all CSV files (bulk import) in a folder, update the file name to each related record (field name: FileName) and then move the CSV files to a archive folder. Thanks
0
Comment
Question by:shieldsco
[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
  • 4
  • 2
7 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 40565607
do you have an Import Specification for importing the csv file?



On Error Resume Next
 Dim csvFile As String, xFile As String, csvFolder As String
 

  csvFolder = "C:\Folder\"  '<<< CHANGE to CORRECT path
  csvFile = Dir(csvFolder & "*.csv")
  While csvFile <> ""
            docmd.transfertext acimportdelim,"importSpecificationName","tablename",csvFolder & csvFile,true
       
            currentdb.execute "update tableName set filename='" & csvfile & "' where filename is null"
            
          Name csvFolder & csvFile As ArchiveFolder & csvFile
         
          csvFile = Dir()
  Wend
0
 
LVL 20

Expert Comment

by:GrahamMandeno
ID: 40565682
I suggest instead of importing each file, you should link it and then run one or more append queries to bring the data into your Access tables.  You will have much more control over things that way.

To move a processed file into your archive folder, just use the Name command with a different folder name:

    Name SourceFolder & FileName As DestinationFolder & FileName

Both folders must be on the same drive for Name to work.

In fact, you could combine the function of importing with the rename loop in your last post I answered.  Then, having imported the data from the file with the old name, rename it into the archive folder with the new name:

    Name SourceFolder & OldFileName As DestinationFolder & NewFileName

Graham Mandeno [Access MVP 1996-2015]
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40565699
To create the Import Specification
   1) Click on external data> text file which then opens another window called "Get external data - Text file"
   2) Use radio button to select "Import the source data into a new table in the current database"
   3) specify the source of the file using the browse procedure then click OK
   4) Choose radio button to select delimited format and then click next
   5) this window allows you to choose delimiter and text qualifier and if first row contains names - click next
   6) This window allows you to type the name of the field in the Field Name column, choose data type, and if you want field indexed - also can choose to skip field - then click next
   7) This window allows you to add primary key or designate field as such - click next
   8) Click on ADVANCED button
   9. in the import specification window
   type the name of the field in the Field Name column
   (here you can use the field names of the destination table, specify data type,
   check the box Skip if you do not want to import the column)
   10 click save as, give the specification a name <-- this is the specification name that you will use in the command line below


 DoCmd.TransferText acImportDelim, "ImportSpecificationName", "TableName", "C:\folderName\myText.txt" , True
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

Author Comment

by:shieldsco
ID: 40566287
Rey - code works for the most part however the files are not being move to an archive folder
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40566308
post the codes that YOU are using.

<code works for the most part> which part is not working?

i can't guessed it if you are not providing detail information.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40566309
did you define the archiveFolder

dim archiveFolder as string
archiveFolder="c:\xxxx\"
0
 

Author Closing Comment

by:shieldsco
ID: 40566373
Very Good
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

636 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