Results 1 to 5 of 5

Thread: Excel print query

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    3

    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.

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    3

    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

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    3

    Re: Excel print query

    No ideas?

  5. #5
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    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
  •  



Click Here to Expand Forum to Full Width