Log in

View Full Version : Macro To Importing Several CSV Files into Access?



LucasLondon
04-02-2007, 08:20 AM
Hi,

I have about 25 CSV files located in a folder that I want to open in Access as separate tables within one database. All files are identical in the sense that they all contain only two fields (Colum 1 = date field, column 2 = data), the top rows contains column headers. The only thing that is different between the files in the data content and so the length of fields (number of rows).

Opening/importing each file is taking a while and was wondering if I could import all the files using some kind of macro? I'm thinking this should be easy given that I have to go through identical steps to import each file:

1) Get external Data - Import File and select my file
2) Select Comma Delimited in the next window
3) Click first row Contains field names in next window
4) Click import into a new table in next window
5) Do not assign a Primary key

I am completely new to macros for Access ? do not even now how to record one! So any help will be much appreciated.

Thanks,

Lucas

stanl
04-02-2007, 09:16 AM
I am completely new to macros for Access ? do not even now how to record one! So any help will be much appreciated.

Lucas

I don't think there is a record macro option for Access. If all files are essentially the same, my advice is to Google "schema.ini" which permits writing a generic module for importing. Then post a sample to get some help. Stan

OBP
04-02-2007, 09:49 AM
Lucas the attached database has a form with a command button the imports a CSV File using a Specification, this can simply be repeated 25 time for your files by changing the File and table names.
You can create and save a specification using the File>Import>Get External Data using the "advanced" button.
To access the VBA code open the form in design mode and on the Command Buttons Properties click the Event Tab, click the After Update Event Procedure and then click the 3 small dots that appear on the right hand side.