-----Original Message-----
Bob
First, you say your code creates a new table for every file you import.
I can't see how this can happen. The snippet below is from the code you
posted. The Do ... Loop iterates through all the .txt files in the
folder without changing the value of mytable, so they must all be
imported to the one table. I pasted it into my test database and that's
what it did.
myfile = Dir(mypath & "*.txt")
Do While myfile <> ""
'This will import ALL the excel files (one at a time,
'but automatically) in this folder.'
DoCmd.TransferText acImportDelim, "Tab_Spec", _
mytable, mypath & myfile
myfile = Dir
Loop
So I don't understand what's happening here, unless the code you posted
is different from what you're actually running.
Second, you say the procedure uses the same field names when you import
the files from another folder. This is probably because you're still
using the same import specification - "Tab_Spec" - and the field names
are defined in that. If you want different field names in the table
created from each folder, you'll have to use a different import
specification for each.
I tried using the code and it creates a table for every
file I import. I need it to import all the files in each
folder to one table which I name. Then I am going to
change folders, and I need it to import all the files in
the new folder to a table I name. That is why a created
the variable 'mytable' because I can name it anything I
want. If I am importing everything into the same table,
why does the data change and the column headers stay the
same?
Thank You,
Bob
-----Original Message-----
Hi Bob,
Your loop below imports all the files to a single table
called
"mytable", so there's no possiblity of the field (column)
names
changing. If you want each different chunk of the
imported data to have
its own column names, you need to import each file to a
new table. For
instance you could use something like this to name each
table after the
file imported to it:
DoCmd.TransferText acImportDelim, "Tab_Spec", _
Left(myfile, InStr(myfile, ".") - 1), _
mypath & myfile
Of course the above assumes that the import
specification "Tab_Spec"
doesn't define field names itself but imports them from
the header row
of the file.
On Wed, 21 Jul 2004 06:43:58 -0700, "Bob"
myfile = Dir(mypath & "*.txt")
Do While myfile <> ""
'This will import ALL the excel files (one at a
time,
but automatically) in this folder.'
DoCmd.TransferText acImportDelim, "Tab_Spec",
mytable,
mypath & myfile
myfile = Dir
Loop
--
John Nurick [Microsoft Access MVP]
Please respond in the newgroup and not by email.
.
--
John Nurick [Microsoft Access MVP]
Please respond in the newgroup and not by email.
.