Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

import textfile into access-table

Status
Not open for further replies.

12345s

Programmer
Dec 9, 2002
3
AT
hi i wrote following sub to import a number of textfiles into a table:
Sub import()
Dim i As String
i = 0
Dim filename As String


While i < 158
filename = &quot;C:\&quot; + i + &quot;.txt&quot;

DoCmd.TransferText acImportDelim, , &quot;tbl_import&quot;, filename, 1
i = i + 1
Wend


End Sub

the first line of the file contains the fieldnames, divided by tabs and spaces. they are equal to the tables fieldnames.
if i process the sub, i get following error-msg: &quot;Field:&quot;Myfiel1_myfield2_myfield3&quot; does not exist.

why does access not recognize the fieldnames?

thanx for your help
 
i replicated your stuff, but did not get an error. however i got just ONE FIELD in my table with all the data separated by little boxes (tabs).

instead i concocted an Import Specification. do you know what this is? I suggest you do the same. Manually import in one of the text files. near the end of the wizard, choose ADVANCED and then SAVE AS. name it something. here is my code rewritten, using my import spec which i called &quot;ImportSpec&quot;

DoCmd.TransferText acImportDelim, &quot;ImportSpec&quot;, &quot;tbl_import&quot;, filename, 1

this worked just fine. so try that and let us know how it goes. if still bad, please copy the first coupla rows of your text file here so we can see.
 
the thing with the specification worked well, but only if there are the same columns in every file. i have to deal with files, where only some of the table's columns can be found.
j
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top