Importing Only Certain Columns of Text Files into Access

B

bsmith1111

Hello. I'm trying to import about 15 columns from a tab-delimited text
file with about 250 columns and around 10,000 records (I need it
automated as I do it on a regular basis). I've spent the last few days
trying everything I can think of....here's what I've got so far.

1) Use an excel macro to import the whole thing and delete unneeded
columns. Unfortunately I could not get the macro to work with so many
columns because the line of code would be too long (I also tried a
second time by "skipping" the unneeded columns in the import- still did
not work)

2) Import the text file using the information in the help file. I went
ahead and created the table "Main:Data" and put the columns I wanted in
there. I didn't think it would work, and I was right.
Here was my line of code:

DoCmd.TransferText acImportDelim, "Main:Data", "c:\Documents and
Settings\All Users\Documents\Main\MainData.txt", -1

3) Somehow use a schema.ini file that is automatically created (got
this from http://www.devx.com/tips/Tip/12566 ) in conjunction with
Access directly. I think this is the thing that would really work. I've
already gotten the schema file for the entire file. My theory is that I
could edit the automatically created schema.ini file by taking out the
unneeded columns and somehow incorporate that into some of my visual
basic code, but I can not find much information on this. If this is the
way to go, I think it would be the best to use in the short and long
runs and also the fastest.


Thank you for your time.

B. Smith
 
K

KARL DEWEY

Build a table with the fields you need. Link the text file. make an append
query from the linked text to the table.
 
D

dd

You can import everything into a temp table, then select the needed
fields into a different table.

docmd.transferText acImportDelim, "specs Name", "tablename1", "filename", -1

docmd.SetWarnings false
docmd.runsql "insert into tablename2 select field1, field2,.... from
tablename2"
docmd.SetWarnings true

-Duy
 

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