Results 1 to 12 of 12

Excell cell in sql where clause

Threaded View

  1. #1
    Registered User
    Join Date
    05-25-2011
    Location
    Ireland
    MS-Off Ver
    Excel 2007
    Posts
    7

    Question Excell cell in sql where clause

    hi guys

    complete newbie to this - looking to create a pivot table from an mysql db hosted remotely, i have everything working at the moment but i would like to expand on it so that a user can enter a date on the excel sheet and click refresh and the query will use the date range from that cell

    eg select * from table1 where date = C1

    this is very sloppy but i've got this far
    Sub SetStartDate()
    Dim rStartDate As Range
        Set rStartDate = Range("D1")
    End Sub
    Sub Macro1()
    '
    ' Macro1 Macro
    '
    ' Keyboard Shortcut: Ctrl+Shift+M
    '
        
        With ActiveWorkbook.Connections("sales_weekly").ODBCConnection
            .BackgroundQuery = True
            .CommandText = Array( _
            "SELECT * FROM `db`.`table1` WHERE `Month` = ") rStartDate
            .CommandType = xlCmdSql
            .Connection = "ODBC;DSN=Database;"
            .RefreshOnFileOpen = False
            .SavePassword = False
            .SourceConnectionFile = ""
            .ServerCredentialsMethod = xlCredentialsMethodIntegrated
            .AlwaysUseConnectionFile = False
        End With
        With ActiveWorkbook.Connections("table1")
            .Name = "table1"
            .Description = "Last Week"
        End With
    End Sub

    any help with this would be greatly appreciated!!! thanks
    Last edited by romperstomper; 05-26-2011 at 07:54 AM. Reason: tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1