Command and syntax to import .txt files to Ms Access table?

G

Guest

I have a Microsoft Access Database and have the structure defined.
Currently, I manually select the Import function of Microsoft Access to
import 9 .txt files into one of the table in that Access database (before I
import the 9 .txt files, I need to manually delete all the records of that
table).

Could anyone tell the Microsoft Access command and syntax to
1. delete all records of that table AND
2. import the 9 .txt files into that table .

Thanks.
 
D

Dirk Goldgar

Terence said:
I have a Microsoft Access Database and have the structure defined.
Currently, I manually select the Import function of Microsoft Access
to import 9 .txt files into one of the table in that Access database
(before I import the 9 .txt files, I need to manually delete all the
records of that table).

Could anyone tell the Microsoft Access command and syntax to
1. delete all records of that table AND
2. import the 9 .txt files into that table .

To delete all records from a table named "Table1":

CurrentDb.Execute "DELETE * FROM Table1", dbFailOnError

To import a text file, you can use the DoCmd.TransferText method --
details in the online help. If the text files are simple,
comma-delimited text, you don't need to do much more than that. If they
are fixed-field files, though, you need to tell Access how to parse them
into fields. You'll make your life simpler if you go through the manual
import process once, but before finishing the import, click the
Advanced... button on the import wizard dialog and save the import
specification. Then later, when you use DoCmd.TransferText to import
each file, you can specify the name of that import specification to tell
Access how to parse out the fields.
 

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

Top