LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Output sql query results to text file

I'm using Execl 2000 and am trying to write a macro that will write query
results to a text file rather than return the results to an excel
spreadhseet. Anyone know how to do this? Any help would be greatly
appreciated! Here is the code I have now that returns the query results to a
spreadsheet

Sub refresh_plc()
sql = "select max(day) from dataroom_plc_data "
DoQuery ("D4")
End Sub

-----------

Sub DoQuery(dest As String)
'Create new query

Range(dest).Select
rindex = Selection.Row
cindex = Selection.Column
Dim connstr As String
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
Dim cn As ADODB.Connection
connstr = "User ID=me;Password=pwd;Data Source=database;Provider=MSDAORA.1"
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.Open (connstr)
rs.Open sql, cn
Cells(rindex, cindex).CopyFromRecordset rs
End Sub
 
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
Checkbox - Output results to a csv file Ephraim Excel Worksheet Functions 4 March 31st 10 03:51 PM
output to the same line in a Text file? Bernard Excel Discussion (Misc queries) 2 November 25th 09 08:12 PM
Formatted output to text file simonc Excel Programming 1 December 15th 06 12:19 PM
Open CSV file, format data and write output to a text file. BristolBloos Excel Programming 1 October 18th 05 03:50 PM
Output color to a text (rtf) file Wild Bill[_3_] Excel Programming 2 November 19th 04 11:05 PM


All times are GMT +1. The time now is 11:52 PM.

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

About Us

"It's about Microsoft Excel"