
Originally Posted by
romperstomper
Have you checked the values of From and Untill? Also, have you tried recording a macro of setting up this connection? (or is that what this is - if so, what was the original code?)
From and untill are in the format dd/mm/yyy and seem ok to me. Here is the original code of the recording:
Sheets("Sheet1").Select
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(Array( _
"ODBC;DSN=AR System ODBC Data Source;ARServer=os-service-management.uk.logica.com;ARServerPort=6512;UID=pricejo;;ARAuthentication=;ARU" _
), Array("seUnderscores=1;SERVER=NotTheServer")), Destination:=Range("$A$1")). _
QueryTable
.CommandText = Array( _
"SELECT HPD_Help_Desk.Incident_Number, HPD_Help_Desk.Description, HPD_Help_Desk.Company, HPD_Help_Desk.First_Name, HPD_Help_Desk.Last_Name, HPD_Help_Desk.Priority, HPD_Help_Desk.Status, HPD_Help_Desk.S" _
, _
"LM_Status, HPD_Help_Desk.Last_Resolved_Date" & Chr(13) & "" & Chr(10) & "FROM HPD_Help_Desk HPD_Help_Desk" & Chr(13) & "" & Chr(10) & "WHERE (HPD_Help_Desk.Company='DCWR') AND (HPD_Help_Desk.Status>='Resolved') AND (HPD_Help_Desk.Last_Resolved_Date>{ts '20" _
, _
"11-01-01 00:00:00'} And HPD_Help_Desk.Last_Resolved_Date<{ts '2011-02-26 00:00:00'})" & Chr(13) & "" & Chr(10) & "ORDER BY HPD_Help_Desk.Last_Resolved_Date, HPD_Help_Desk.First_Name" _
)
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Table_Query_from_AR_System_ODBC_Data_Source"
.Refresh BackgroundQuery:=False
End With
ActiveWindow.SmallScroll Down:=-15
End Sub
I just re-made this because I didn't have a copy of the original code dorry, but I followed the same steps in creating this so it should be the same.
I replaced the dates with the variables from and untill again but no luck.
Bookmarks