R
RichardLOZ
I am trying to run an ODBC query to an informix database. I have done this
is previous organisations without any trouble, but for some reason I am now
getting errors.
Run-time error '1004'
Application-defined or object-defined error
And for the life of me I cant work it out.
CODE:
Sub CreateQT()
Dim ConnectStr As String
Dim SqlStr As String
Dim Statsqry As QueryTable
ConnectStr =
"ODBC;DSN=CMS;UID=xxx;PWD=xxx;Database=store7;FetchBufferSize=30;Host=xx.x.xx.xx;NoLoginBox=No;Options=;Protocol=TCP/IP;ReadOnly=Yes;ServerOptions=;ServerType=Informix 2000"
TodayStr = Format(Date, "yyyy-mm-dd")
YestStr = Format(Date - 1, "yyyy-mm-dd")
SqlStr = "SELECT hsplit.row_date, synonyms.item_name,
Sum(hsplit.acdcalls), Sum(hsplit.acceptable), Sum(hsplit.abncalls),
Sum(hsplit.abntime), Sum(hsplit.holdcalls), Sum(hsplit.holdtime),
Max(hsplit.maxocwtime), Sum(hsplit.acdtime), Sum(hsplit.acwtime),
Sum(hsplit.transferred), Sum(hsplit.anstime), Sum(hsplit.callsoffered)" &
Chr(13) & "" & Chr(10) & "FROM root.hsplit hsplit, root.synonyms synonyms" &
Chr(13) & "" & Chr(10) & "WHERE synonyms.value = hsplit.split AND
((synonyms.item_type='split') AND (hsplit.row_date={d '" & YestStr & "'}) AND
(hsplit.split>=22 And hsplit.split<=31))" & Chr(13) & "" & Chr(10) & "GROUP
BY hsplit.row_date, synonyms.item_name, hsplit.split" & Chr(13) & "" &
Chr(10) & "ORDER BY hsplit.split"
Set Statsqry = Sheets(1).QueryTables.Add(Connection:=ConnectStr,
Destination:=Range("A1"))
With Statsqry
.CommandText = SqlStr
.FieldNames = False
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub
Any assistance with this would be much appreciated. Thanks
Richard
is previous organisations without any trouble, but for some reason I am now
getting errors.
Run-time error '1004'
Application-defined or object-defined error
And for the life of me I cant work it out.
CODE:
Sub CreateQT()
Dim ConnectStr As String
Dim SqlStr As String
Dim Statsqry As QueryTable
ConnectStr =
"ODBC;DSN=CMS;UID=xxx;PWD=xxx;Database=store7;FetchBufferSize=30;Host=xx.x.xx.xx;NoLoginBox=No;Options=;Protocol=TCP/IP;ReadOnly=Yes;ServerOptions=;ServerType=Informix 2000"
TodayStr = Format(Date, "yyyy-mm-dd")
YestStr = Format(Date - 1, "yyyy-mm-dd")
SqlStr = "SELECT hsplit.row_date, synonyms.item_name,
Sum(hsplit.acdcalls), Sum(hsplit.acceptable), Sum(hsplit.abncalls),
Sum(hsplit.abntime), Sum(hsplit.holdcalls), Sum(hsplit.holdtime),
Max(hsplit.maxocwtime), Sum(hsplit.acdtime), Sum(hsplit.acwtime),
Sum(hsplit.transferred), Sum(hsplit.anstime), Sum(hsplit.callsoffered)" &
Chr(13) & "" & Chr(10) & "FROM root.hsplit hsplit, root.synonyms synonyms" &
Chr(13) & "" & Chr(10) & "WHERE synonyms.value = hsplit.split AND
((synonyms.item_type='split') AND (hsplit.row_date={d '" & YestStr & "'}) AND
(hsplit.split>=22 And hsplit.split<=31))" & Chr(13) & "" & Chr(10) & "GROUP
BY hsplit.row_date, synonyms.item_name, hsplit.split" & Chr(13) & "" &
Chr(10) & "ORDER BY hsplit.split"
Set Statsqry = Sheets(1).QueryTables.Add(Connection:=ConnectStr,
Destination:=Range("A1"))
With Statsqry
.CommandText = SqlStr
.FieldNames = False
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub
Any assistance with this would be much appreciated. Thanks
Richard