Hi all,
I've got the following query running in Excel.
However, it fails and highlights the line,
This has only started happening since I replaced hard coded dates in the query with the format date. I did this as I want the user to enter the dates.
Can anyone give me a hand with solving this? I've tried a few things but to no avail!
Thanks in advance,
Woody
I've got the following query running in Excel.
Code:
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=SQLSvr;Description=Connection to SQL Server (SQLSVR);UID=sa;PWD=password;APP=Microsoft Office 2003;WSID=SWOODWARD;DATABASE=FMDB;Networ" _
), Array("k=DBMSSOCN")), Destination:=Range("A1"))
.CommandText = Array( _
"SELECT GRNHeader2a.VENDOR_ID, GRNHeader2a.CURRENCY_ID, GRNHeader2a.ID, GRNHeader2a.RECEIVED_DATE, GRNHeader2a.BUY_RATE" & Chr(13) & "" & Chr(10) & "FROM FMDB.dbo.GRNHeader2a GRNHeader2a" & Chr(13) & "" & Chr(10) & "WHERE (GRNHeader2a.INVOICE_ID Is Null) AN" _
, _
"D (GRNHeader2a.CREATE_DATE Between {ts '" & Format(StartDate, "yyyy-mm-dd hh:nn:ss") & "'} And {ts '" & Format(EndDate, "yyyy-mm-dd hh:nn:ss") & "'})" _
)
.Name = "Query from SQLSvr"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
However, it fails and highlights the line,
Code:
.Refresh BackgroundQuery:=False
This has only started happening since I replaced hard coded dates in the query with the format date. I did this as I want the user to enter the dates.
Can anyone give me a hand with solving this? I've tried a few things but to no avail!
Thanks in advance,
Woody