Firstly You need to wrap your code!
Secondly looks like your almost there buddy:
Sub Macro1()
Dim MyDate as Date
MyDate = Range("C1").value
With ActiveWorkbook.Connections("sales_weekly").ODBCConnection
.BackgroundQuery = True
.CommandText = Array( _
"SELECT * FROM `db`.`table1` WHERE `Month` = " & MyDate)
.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
However i Notice that the field you are apply the where clause to is called "Month" that what format is that in? e.g "February" or "Feb" or "02" or is it a full date? you'll need to format the value from cell C1 to match the field format and if it contaings letters you'll also have to wrap it in apostraphes (however its spelt?)
E.g.
"SELECT * FROM `db`.`table1` WHERE `Month` = " & Format(MyDate,"DD-MMM-YY"))
Hope this helps?
Bookmarks