Importing text files

  • Thread starter Thread starter Va
  • Start date Start date
V

Va

I am trying to import tab delimited text file into a
recordset. The code I am using is

conn_string = "Driver={Microsoft Text Driver (*.txt;
*.csv)};Dbq=c:\AMPS\Files\2538;DefaultDir=c:\temp;Extension
s=asc,csv,tab,txt;"

Set con = New ADODB.Connection
Set rst = New ADODB.Recordset

con.ConnectionString = strcs
con.Open


rst.Open "zzz.txt", strcs, adOpenStatic,
adLockReadOnly, adCmdTable


If any of the columns in the file is more than 256
characters, then open recordset fails. The message
is "Run-time error - [Microsoft][ODBC Text Driver] The
size of a field is too long". Is there any way of reading
fields with more than 256 characters?

Thanks
 
¤ I am trying to import tab delimited text file into a
¤ recordset. The code I am using is
¤
¤ conn_string = "Driver={Microsoft Text Driver (*.txt;
¤ *.csv)};Dbq=c:\AMPS\Files\2538;DefaultDir=c:\temp;Extension
¤ s=asc,csv,tab,txt;"
¤
¤ Set con = New ADODB.Connection
¤ Set rst = New ADODB.Recordset
¤
¤ con.ConnectionString = strcs
¤ con.Open
¤
¤
¤ rst.Open "zzz.txt", strcs, adOpenStatic,
¤ adLockReadOnly, adCmdTable
¤
¤
¤ If any of the columns in the file is more than 256
¤ characters, then open recordset fails. The message
¤ is "Run-time error - [Microsoft][ODBC Text Driver] The
¤ size of a field is too long". Is there any way of reading
¤ fields with more than 256 characters?

Assuming you have a schema.ini file you will probably need to define this field as Memo or LongChar
(if using ODBC):

[TabDelimitedFile.txt]
ColNameHeader=False
Format=TabDelimited
CharacterSet=ANSI

Col1=Field1 Integer
Col2=Field2 Integer
Col3=Field3 Integer
Col4=Field4 Integer
Col5=Field5 Integer
Col6=Field6 Memo

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcjetsdk_98.asp


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Back
Top