Forum Discussion
Importing Multiple Text Files
Hi All,
Is there a way to import multiple text file in MS access database. I have more than 50 - 60 file every time I need to import in access database.
- mrman17Copper Contributor
I know I am late to the party with this, but I thought I'd add my solution for anyone else with the same "problem" in the hope it will help them.
You will need to use the command prompt and navigate to the folder containing your data files.
At the prompt, type the following (assuming the extension is "csv" - change this to "txt" if needed):
copy /b *.csv _allfiles.csv
This will copy (or merge) all the files with the defined extension into one file. The underscore at the start of the filename will put it at the top of the list to make it easier to find.
This does rely on all the files having the same column structure, and you may have to go through the generated file to remove any column headers.
- Daniel_AzzamCopper ContributorThank you
- Do the files always have the same names? Are you just importing the latest version of each text file?
If so, then you can save the file names in a table and loop through the files in turn to import them
OR link the text files instead of importing them - then they will always be up to date- sathishkmCopper ContributorFiles names are different.
example :
abc.txt
bs.txt
ddn.txt
73m.txt
hh.txt
Likewise the file name will be.
- George_HepworthSilver Contributor
The short answer, of course, is yes you can do that.
The long answer is that it will require VBA and functions that can enumerate files in a folder (preferably using FileScripting, although old school Dir is feasible). Then, once you've created a list of those files in a temp table, you can loop through the list importing each one in turn.
However, it also depends on WHY you need to do this. If the files are constantly being replaced by an external process, such as output from a testing station, or orders from an online store application, then you can't just link to them and use them that way, not easily at any rate.
I believe that at least two of the projects I completed for clients over the years would be similar to this, but each involves multiple, significant VBA functions and subs and would not be something easily passed through a forum.
So, define the nature of the requirement a little more fully and we can maybe offer more ideas.
- sathishkmCopper ContributorCan you post the VBA code
- George_HepworthSilver ContributorIt's in half a dozen procedures scattered over different modules and it is highly specific to one environment. It took a couple of weeks to work it all out and implement the supporting form.
I can make it available as is, but it'll be up to you to implement the concepts.
- George_HepworthSilver ContributorBesides, you haven't yet responded to the questions Colin asked, nor my request for details. It's a considerable amount of work to go to on the possibility it would be appropriate.
- sathishkmCopper ContributorEveryday I will get lot of text file.
Example:
bs.txt
ddn.txt
hh.txt
73m.txt
likewise so on. My task is to import all these tiles in MS Access database. Where I can work on these files. If I have 50 files today. I have to manual click the each text file and import them. It's very time consuming job.