If the TransferText function works, why don't you just delete the content of the table before you do the import?
currentdb.Execute "DELETE * FROM tblYourTableHere"
HTH,
Michael
Main Topics
Browse All TopicsI would like to import a very large csv file into a blank table in access that has been set up with field names. The csv file does not contain field names. Can this be done with the TransferText function of a macro or can it be done using vba? I have tried the TransferText function and set 'has field names' to no. Evidentally this function uses an append so it won't work with csv files. THANKS!!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
First you need to create an import specification.
Do the tthe first transfer of data using
File>Get External Data>Import
Select from Files of type Text type
Locate where your csv files and select
Click import
Just follow the instructions on the Import text wizard.
On the last window, when Next is grayed select Advanced ,
this will take you to the Import Spec window, save the spec.
now you can use the import spec using
DoCmd.TransferText acImportDelim, "ImportSpec", "TableName", "C:\FileName.CSV"
What would like to try is to use an import spec and transfer text to get the data imported with the auto-assigned generic field names (Field1, Field2, etc.). Then could I append this to a blank table with assigned field names such as Name, Address, etc. using vba. Remember that there are 120 fields, so I'm looking for some sql or something that will force Field1 into Name, Field2 into Address, etc.
I have tried this code (slightly altered for my purposes):
DoCmd.TransferText acImportDelim, "ImportSpec", "TableName", "C:\FileName.CSV", False,""
But my import spec is has my fields named Field1, Field2, Field3, etc. and my table has fields named Name, Address, Phone, etc. Even with the FALSE I still get a "Field (Field1) doesn't exist in table" error message.
Is it possible to have an sql statement force the first field of one table into the first field of another and so on without having to name the fields???
This will generate the same error as when I try the TransferText...
DoCmd.RunSQL ("INSERT INTO CustomNameFs SELECT GenericNameFs.* FROM GenericNameFs")
I agree with GRayl. Just import the file into a temp table, using default options which should generate field names like Field1, field2... field100 ... fieldx, then use a query to fetch data from temp to the table you want to import into - should look something like:
insert into DestinationTable (employeeNo, address, tel, email ... ) select (field1, field2, ... fieldx) from tempTable
it's true that the first time around it's gonna be really painful, but then the subsequent operations are much easier.
Have fun!
Y.C.
What I have gathered from this is that it is not possible to force data (originally 150k csv records w/ 120 fields) from the first field of one table into the first field of a different table without defining the field names (be it in a query, an import spec, or sql). I went ahead and just defined all fields in the import spec. Points to GRayL for the assistance.
Thanks. By linking to the text file, Access assigned default Field Names consistently. Thus the same type of table next month will have the same name defaults. You need the append query to move the data over to your permanent table. You can reuse the append query as long as the field types and number do not change. Good luck.
Ray :)
Business Accounts
Answer for Membership
by: dkmj17Posted on 2004-07-20 at 09:12:41ID: 11594450
Well- are you doing it only once, or a number of times? To do it once, it is certainly easiest just to use the import method, to do it a number of times, transfertext works... docmd.transfertext in VBA... You may also need to create an import specification, which is done using the import wizzard, and then use that as a part of transfer text...
Mike