+ Reply to Thread
Results 1 to 3 of 3

Can't select field in ADO with Text Driver

  1. #1
    Greg Lovern
    Guest

    Can't select field in ADO with Text Driver

    In Excel 2003, I'm using ADO to read a CSV text file. It works fine
    unless I try to specify a specific field in the SQL statement:

    Function GetList()

    Dim rs As ADODB.Recordset
    Dim conn As ADODB.Connection
    Dim fd As ADODB.Field
    Dim myarrray() As String

    Set rs = New ADODB.Recordset
    Set conn = New ADODB.Connection

    conn.Open "DRIVER={Microsoft Text Driver (*.txt; *.csv)};" & _
    "DBQ=" & ThisWorkbook.Path & ";"

    'this works great, BUT I need to be able to get just one field..
    'rs.Open "select * from test.csv", conn

    'this returns the error "Too few parameters. Expected 1.":
    Set rs = conn.Execute("select * from test.csv where fieldname =
    'Field2'")

    'this works great, BUT I need to be able to get just one field..
    'Set rs = conn.Execute("select * from test.csv")

    myarray = rs.GetRows

    Set rs = Nothing
    Set conn = Nothing
    End Function


    In the CSV file, the first row is the field names:

    Field1,Field2,Field3
    Rec1Fld1,Rec1Fld2,Rec1Fld3
    Rec2Fld1,Rec2Fld2,Rec2Fld3
    Rec3Fld1,Rec3Fld2,Rec3Fld3


    What do I need to do to return just the one field?



    Thanks,

    Greg


  2. #2
    Tim Williams
    Guest

    Re: Can't select field in ADO with Text Driver

    "select Field2 from test.csv"


    Tim

    "Greg Lovern" <gregl@gregl.net> wrote in message
    news:1143586122.321389.51670@j33g2000cwa.googlegroups.com...
    > In Excel 2003, I'm using ADO to read a CSV text file. It works fine
    > unless I try to specify a specific field in the SQL statement:
    >
    > Function GetList()
    >
    > Dim rs As ADODB.Recordset
    > Dim conn As ADODB.Connection
    > Dim fd As ADODB.Field
    > Dim myarrray() As String
    >
    > Set rs = New ADODB.Recordset
    > Set conn = New ADODB.Connection
    >
    > conn.Open "DRIVER={Microsoft Text Driver (*.txt; *.csv)};" & _
    > "DBQ=" & ThisWorkbook.Path & ";"
    >
    > 'this works great, BUT I need to be able to get just one field..
    > 'rs.Open "select * from test.csv", conn
    >
    > 'this returns the error "Too few parameters. Expected 1.":
    > Set rs = conn.Execute("select * from test.csv where fieldname =
    > 'Field2'")
    >
    > 'this works great, BUT I need to be able to get just one field..
    > 'Set rs = conn.Execute("select * from test.csv")
    >
    > myarray = rs.GetRows
    >
    > Set rs = Nothing
    > Set conn = Nothing
    > End Function
    >
    >
    > In the CSV file, the first row is the field names:
    >
    > Field1,Field2,Field3
    > Rec1Fld1,Rec1Fld2,Rec1Fld3
    > Rec2Fld1,Rec2Fld2,Rec2Fld3
    > Rec3Fld1,Rec3Fld2,Rec3Fld3
    >
    >
    > What do I need to do to return just the one field?
    >
    >
    >
    > Thanks,
    >
    > Greg
    >




  3. #3
    Greg Lovern
    Guest

    Re: Can't select field in ADO with Text Driver

    Thanks!

    Greg


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1