|
-
Apr 6th, 2006, 09:02 AM
#1
Thread Starter
New Member
Excel print query
how do i store query results into variables and then print those variables to specific cells in an excel worksheet?
I am trying to query a database using VBA and then manipulate the data and place it in specific places ...
thanks.
-
Apr 6th, 2006, 09:11 AM
#2
Re: Excel print query
Welcome to the forums
Can you post the code that you have so far.
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Apr 6th, 2006, 09:35 AM
#3
Thread Starter
New Member
Re: Excel print query
thanks for the welcome.
this is what i have started. Thanks for the help.
Sub GetTrans()
Dim i As Integer
Dim iNumCols As Integer, iNumRows As Integer
Dim begin_date As Variant
begin_date = Sheets("JPY").Range("AL12").Value
end_date = Sheets("JPY").Range("AL13").Value
On Error GoTo ErrHandler
Sheets("Trans").Select
Range("A10").Select
If (Range("A10").Value <> vbNullString) Then
iNumRows = Sheets("FuturesTrans").Range("A10").End(xlDown).Row
iNumCols = Sheets("FuturesTrans").Range("A10").End(xlToRight).Column
Sheets("FuturesTrans").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=pass;APP=Microsoft® Query;" _
, Destination:=Range("A10"))
.CommandText = Array( _
"SELECT statement" _
)
.Name = "Futures 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 Futures Transactions"
End Sub
-
Apr 6th, 2006, 04:15 PM
#4
Thread Starter
New Member
-
Apr 6th, 2006, 04:17 PM
#5
Re: Excel print query
I'm still not clear what you need to do. The above looks fine. and it gives you a table of data. What do you now need to do with the resulting table?
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|