Hi all,
I'm trying to run a query that uses two date parameters from user input. This is my code for the query:
Unfortunately I'm getting a General ODBC error when I run it and the error is highlighting the line
I'm trying to run a query that uses two date parameters from user input. This is my code for the query:
Code:
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=SQLSvr;Description=Connection to SQL Server (SQLSVR1);APP=Microsoft Office 2003;WSID=SWOODWARD;DATABASE=FMDB;Network=DBMSSO" _
), Array("CN;Trusted_Connection=Yes")), Destination:=Range("A1"))
.CommandText = Array( _
"SELECT LABOR_TICKET.TRANSACTION_DATE, LABOR_TICKET.WORKORDER_BASE_ID, LABOR_TICKET.RESOURCE_ID, LABOR_TICKET.EMPLOYEE_ID, LABOR_TICKET.HOURS_WORKED, SHOP_RESOURCE.BUR_PER_HR_RUN, EMPLOYEE.FIRST_NAME, " _
, _
"EMPLOYEE.LAST_NAME" & Chr(13) & "" & Chr(10) & "FROM FMDB.dbo.EMPLOYEE EMPLOYEE, FMDB.dbo.LABOR_TICKET LABOR_TICKET, FMDB.dbo.SHOP_RESOURCE SHOP_RESOURCE" & Chr(13) & "" & Chr(10) & "WHERE LABOR_TICKET.RESOURCE_ID = SHOP_RESOURCE.ID AND LABOR_TICKET.EMPLOY" _
, _
"EE_ID = EMPLOYEE.ID AND ((LABOR_TICKET.WORKORDER_LOT_ID='SO1') AND (LABOR_TICKET.CREATE_DATE Between {ts '" & Format(Date1, "dd-mm-yyyy hh:nn:ss") & "'} And {ts '" & Format(Date2, "dd-mm-yyyy hh:nn:ss") & "'}) OR (LABOR_TICKET.WORKORDER_LOT_ID='FO1')" _
, _
" AND (LABOR_TICKET.CREATE_DATE Between {ts '" & Format(Date1, "dd-mm-yyyy hh:nn:ss") & "'} And {ts '" & Format(Date2, "dd-mm-yyyy 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
Unfortunately I'm getting a General ODBC error when I run it and the error is highlighting the line
Code:
.Refresh BackgroundQuery:=False
[\Code]
Does anyone have any ideas on this?
Cheers,
Woody