Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Help with SQL and ODBC Text Driver

I have a tab delimited text file (over 300 variables, so I can't stick it
straight into another Excel workbook) and I am trying to use ODBC to connect
to the text file and pull values into an Excel file. The code I have so far
doesn't seem to be picking up the field headers. It'll run when I take off
the criteria, but will break when it comes to the first specific query for a
fieldname. Here's what I have. Can someone hlep please? Thanks a lot!

'===============================================
' start: open connection string to database with data
'===============================================
Dim cn As ADODB.Connection, rs As ADODB.Recordset, strSQL As
String

'!!! This line won't work cos I have the WHERE criteria referencing
a field
strSQL = "SELECT * FROM sourcedata.txt WHERE ACE07 = " & clientCode

' !!! This line will work, but after it opens the recordset, it
doesn't seem to find any fields
' plus I need the data to be specific, so I need the WHERE clause
strSQL = "SELECT * FROM sourcedata.txt"

strFolder = "H:\Excel-Powerpoint\Current\"

Set cn = New ADODB.Connection

cn.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
"Dbq=" & strFolder & ";" & _
"Extensions=asc,csv,tab,txt;HDR=Yes"

If cn.State < adStateOpen Then Exit Sub

Set rs = New ADODB.Recordset

rs.Open strSQL, cn, adOpenForwardOnly, adLockReadOnly, adCmdText

'==============================================
' start: transferring values to XLS source
'==============================================
sourceWS.Range("F4").Value = rs("Female")

[...more code to transfer values to XLS]

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Help with SQL and ODBC Text Driver

Have a look he
http://tinyurl.com/2jm5p

RBS


"et10yl" wrote in message
...
I have a tab delimited text file (over 300 variables, so I can't stick it
straight into another Excel workbook) and I am trying to use ODBC to
connect
to the text file and pull values into an Excel file. The code I have so
far
doesn't seem to be picking up the field headers. It'll run when I take
off
the criteria, but will break when it comes to the first specific query for
a
fieldname. Here's what I have. Can someone hlep please? Thanks a lot!

'===============================================
' start: open connection string to database with data
'===============================================
Dim cn As ADODB.Connection, rs As ADODB.Recordset, strSQL As
String

'!!! This line won't work cos I have the WHERE criteria referencing
a field
strSQL = "SELECT * FROM sourcedata.txt WHERE ACE07 = " & clientCode

' !!! This line will work, but after it opens the recordset, it
doesn't seem to find any fields
' plus I need the data to be specific, so I need the WHERE clause
strSQL = "SELECT * FROM sourcedata.txt"

strFolder = "H:\Excel-Powerpoint\Current\"

Set cn = New ADODB.Connection

cn.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
"Dbq=" & strFolder & ";" & _
"Extensions=asc,csv,tab,txt;HDR=Yes"

If cn.State < adStateOpen Then Exit Sub

Set rs = New ADODB.Recordset

rs.Open strSQL, cn, adOpenForwardOnly, adLockReadOnly, adCmdText

'==============================================
' start: transferring values to XLS source
'==============================================
sourceWS.Range("F4").Value = rs("Female")

[...more code to transfer values to XLS]


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
Excel ODBC Driver with ADO TimG Excel Programming 3 February 16th 06 01:50 PM
ODBC Driver/Import Data Andy Excel Discussion (Misc queries) 0 May 12th 05 09:10 PM
xl odbc driver, Excel 2003 johnny_2005 Setting up and Configuration of Excel 0 February 15th 05 10:08 PM
which odbc excel driver is the best? andre Excel Programming 2 June 3rd 04 06:36 PM
ODBC driver file path Random Excel Programming 0 July 24th 03 01:11 PM


All times are GMT +1. The time now is 09:52 AM.

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"