PDA

View Full Version : Import txt with tab



ennas
03-29-2006, 07:19 AM
I have a txtfile that i want to import in a access table. The textfile has separation of spaces.

This is the code i use.

Open "G:\Students\sanne\test.txt" For Input As #TXTFile
Do While Not EOF(TXTFile)
Line Input #TXTFile, TXTLine
TXTLine = Trim(TXTLine)
rst.AddNew
'rst2.AddNew
' your table field, start position and length would go in next line
' the line is then repeated for each field
rst![Extension] = Trim(Mid(TXTLine, 6, 4))
rst!Total_Cost = Trim(Mid(TXTLine, 19, 7))
rst.Update
Loop
Close #TXTFile

The reading in is good, only it takes space with im.

Have somebody a resolution for this.

Thanks

JMG
03-29-2006, 08:03 AM
I import a lot of text files.
My procedure on importing new files:
1. import the file using the import wizard and name the import spec
a. click 'file' - 'get external data' - 'import'
b. next screen change 'files of type:' to text
c. find the file to be imported
d. click on import
e. when the import wizard box appears select whether 'delimited' or 'fixed length' (apparently yours is fixed)
f. click next
g. adjust the lines to fit your field size
h. click on advanced
i. rename the fields and change the data type if wanted or necessary
j. click 'save as' and name the spec or use the default the wizard gives you
k. click 'next' and decide where to put your import
2. create a macro that transfers text into access using the named spec
3. transfer the macro to vba and call the module with a command button
hope this helps