Results 1 to 12 of 12

Excell cell in sql where clause

Threaded View

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

    Re: Excell cell in sql where clause

    i added this line to output to a message box to see what the query looks like and it looks fine

    Sub Macro1()
    
    Dim MyDate As Date
    
    MyDate = Worksheets("Sheet1").Range("D2").Value
    MyDate2 = Format(MyDate, "YYYY-MM-DD")
    brackets = "'"
    Test1 = "SELECT * FROM pivot1month WHERE Date = '" & MyDate2 & "'"
    MsgBox Test1
    
    
    With ActiveWorkbook.Connections("sales").ODBCConnection
      .BackgroundQuery = True
      .CommandText = "SELECT * FROM pivot1month WHERE Date = '" & Format(MyDate, "YYYY-MM-DD") & "'"
      .CommandType = xlCmdSql
      .Connection = "ODBC;DSN=Database;"
      .RefreshOnFileOpen = False
      .SavePassword = False
      .SourceConnectionFile = ""
      .ServerCredentialsMethod = xlCredentialsMethodIntegrated
     .AlwaysUseConnectionFile = False
    End With
    
    With ActiveWorkbook.Connections("sales")
     .Name = "sales"
     .Description = "Last Week"
    End With
    
    End Sub
    really stumped! i appreciate you taking the time to help thought this would be straight forward :s
    Last edited by cacoyle45; 05-26-2011 at 11:12 AM. Reason: addition

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