Importing text files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Va

    #1

    Importing text files

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

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

    Set con = New ADODB.Connectio n
    Set rst = New ADODB.Recordset

    con.ConnectionS tring = 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

  • Paul Clement

    #2
    Re: Importing text files

    On Tue, 2 Sep 2003 22:51:05 -0700, "Va" <vivek_arkalgud @mail.com> wrote:

    ¤ I am trying to import tab delimited text file into a
    ¤ recordset. The code I am using is
    ¤
    ¤ conn_string = "Driver={Micros oft Text Driver (*.txt;
    ¤ *.csv)};Dbq=c:\ AMPS\Files\2538 ;DefaultDir=c:\ temp;Extension
    ¤ s=asc,csv,tab,t xt;"
    ¤
    ¤ Set con = New ADODB.Connectio n
    ¤ Set rst = New ADODB.Recordset
    ¤
    ¤ con.ConnectionS tring = 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):

    [TabDelimitedFil e.txt]
    ColNameHeader=F alse
    Format=TabDelim ited
    CharacterSet=AN SI

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

    http://msdn.microsoft.com/library/de...cjetsdk_98.asp


    Paul ~~~ pclement@amerit ech.net
    Microsoft MVP (Visual Basic)

    Comment

    Working...