Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
sep27
 
Posts: n/a
Default SQL results manipulation


I am trying to write a macro that queries a MS SQL server and kicks out
data in predicable cells -- say start printing results at A10, but I
want to print certain headings above each column as well. AND perhaps
do some calculations and print the results to other worksheets ...

here is what I have:


Sub GetTrans()

Dim i As Integer
Dim iNumCols As Integer, iNumRows As Integer


On Error GoTo ErrHandler

Sheets("Trans").Select
Range("A10").Select

If (Range("A10").Value < vbNullString) Then
iNumRows = Sheets("FuturesTrans").Range("A10").End(xlDown).Ro w
iNumCols = Sheets("FuturesTrans").Range("A10").End(xlToRight) .Column
Sheets("Trans").Range(Cells(1, 1), Cells(iNumRows, iNumCols)).Select
Selection.ClearContents
End If

For i = 1 To ActiveSheet.QueryTables.Count
ActiveSheet.QueryTables(i).Delete
Next

With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER=SQL Server;SERVER=SQL\SQL;UID=User;PWD=password;APP=Mi
crosoft® Query;" _
, Destination:=Range("A10"))
.CommandText = Array( _
"SELECT statement here"
)
.Name = "Transactions Query"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With


Exit Sub

ErrHandler:
MsgBox Err.Description, vbCritical, "Error: Get Transactions"
End Sub






thanks.


--
sep27
------------------------------------------------------------------------
sep27's Profile: http://www.excelforum.com/member.php...o&userid=33206
View this thread: http://www.excelforum.com/showthread...hreadid=530269

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 pick Home and Away results from a list [email protected] Excel Worksheet Functions 5 March 21st 06 09:16 PM
Paste results consecutively within column (based off other worksheet) [email protected] Excel Worksheet Functions 5 March 13th 06 11:54 AM
abdualmohsn almedrahe abdualmohsn ahmad Excel Discussion (Misc queries) 1 November 19th 05 06:32 PM
Date stamp formula results? Tricky problem? mjp Excel Discussion (Misc queries) 0 November 18th 05 04:11 PM
calculating results in formulas Linda Excel Discussion (Misc queries) 9 July 6th 05 09:20 AM


All times are GMT +1. The time now is 07:56 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"