Help needed in merging csv files into one Automatically.

  • Thread starter Thread starter TD
  • Start date Start date
T

TD

Does anyone know of a way to automatically (say Midnight each day) merge all
csv files located in a folder into one file, then import them (append) to a
SQL table?
 
Several ways you could go about doing this.

If you want to create a Master.csv file first then look at using the
FileSystem object to loop through all files and use the Open, Input, Write,
Close methods, example below - Substitute MyFile.csv with the name of each
file in the folder. You can then link to Master.csv and run an append query:

Open "MyFile.csv" For Output As #1
Open "Master.csv" For Input As #2
Write #1, strh1, strh2, strh3 ...
Do While Not EOF(2)
Input #2, str1, str2, str3,...
Write #1, str1, str2, str3, ...
Loop
Close #1
Close #2

If you don't need a Master.csv then use the File System Object to link to
each file in turn and run the append query.

On Error Resume Next
DoCmd.DeleteObject acTable, "tblTemp"
DoCmd.TransferText acLinkDelim, "MySchema", "tblTmp", "MyFile.csv"
DoCmd.OpenQuery "myAppendQuery"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top