Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 224
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Can't select field in ADO with Text Driver

"select Field2 from test.csv"


Tim

"Greg Lovern" wrote in message
ups.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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 224
Default Can't select field in ADO with Text Driver

Thanks!

Greg

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to install two video adapter driver using the same WDDM driver? Able Cox New Users to Excel 1 January 24th 08 12:44 PM
Postscript driver won't print rows that the PCL driver will dziesmer Excel Discussion (Misc queries) 0 December 6th 07 09:21 PM
Select text from a field Bob[_67_] Excel Programming 4 November 2nd 05 10:36 PM
text driver problem taupirho Excel Programming 1 April 29th 05 02:22 PM
HELP!! Populate text in single XL field, or bulk copy text into 1 field filmfatale[_2_] Excel Programming 0 December 9th 03 02:30 PM


All times are GMT +1. The time now is 03:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"