|
Question : Getting ODBC general error on command refresh background query
|
|
Hi, I'm using Microsoft Excel 2000, and making a query through ODBC to a SQL server. I'm quite a newbee, and I had to start with that unfortunately, so perhaps the problem is easy-way sorry. My problem is that on my Excell sheet, I have two sheets running each one one query to the same DB but from different tables. When I run the first query alone I don't have a problem, but when I add the second query, it gaves me a 'runtime error : 1004 general ODBc error' and the VBA point the line .refresh BackgroundQuery:=False from the second query.
The summary is that in total, I will have three sheets with three differents queries that I want to update only by clicking one button on a fourth sheet that contains a summary of the whole datas retrieved from the queries.
I admit that when I was developing the first part only, I had this problem, and I solved it by copying/pasting the exact same code but one line upper (there was one blank line between my End sub and Private sub), I don't understand why but the problem was solved..perhaps could help.
Here is my code:
Sub RefreshQueryBPline()
Dim lignequery As String, lignequery2 As String, tdebut As String, tfin As String tdebut = Format$(Now, "yyyy-mm-dd") + " 07:45:00" tfin = Format$(Now, "yyyy-mm-dd") + " 18:15:00" lignequery = "SELECT iAgentPerformanceStat.Timestamp, iAgentPerformanceStat.AgentLogin, iAgentPerformanceStat.SupervisorLogin, iAgentPerformanceStat.AgentSurName, iAgentPerformanceStat.CallsAnswered, iAgentPerformanceStat.TalkTime, iAgentPerformanceStat.HoldTime, iAgentPerformanceStat.LoggedInTime, iAgentPerformanceStat.NotReadyTime, iAgentPerformanceStat.DNOutExtCalls, iAgentPerformanceStat.DNOutExtCallsTalkTime, iAgentPerformanceStat.CallsReturnedToQ, iAgentPerformanceStat.ShortCallsAnswered , iAgentPerformanceStat.CDNCallsTransferredToCDN FROM blue.dbo.iAgentPerformanceStat iAgentPerformanceStat WHERE (iAgentPerformanceStat.SupervisorLogin='1120') OR (iAgentPerformanceStat.SupervisorLogin='5140') AND (iApplicationStat.Timestamp>={ts '" + tdebut + "'} And iApplicationStat.Timestamp<{ts '" + tfin + "'}) ORDER BY iAgentPerformanceStat.Timestamp" lignequery2 = "SELECT Agent.TelsetLoginID, Agent.SurName, Agent.GivenName, Agent.Department FROM blue.dbo.Agent Agent WHERE (iApplicationStat.Timestamp>={ts '" + tdebut + "'} And iApplicationStat.Timestamp<{ts '" + tfin + "'}) AND (Agent.Department='Compaq Commercial Products FR') OR (Agent.Department='Compaq Commercial Products NL')ORDER BY Agent.Department, Agent.SurName" Put_Recupererlesdatas "Q_Agent Summary", lignequery, 250&, 16 Put_Recupererlesdatas2 "Q_Case Handling Time", lignequery2, 9000&, 5
End Sub Private Sub Put_Recupererlesdatas(ByVal temp As String, ByVal lignequery As String, ByVal ligne As Integer, ByVal colonne As Integer)
Dim queryBP As QueryTable ThisWorkbook.Activate Sheets(temp).Activate Range(Cells(1, 1), Cells(ligne, colonne)).Select Selection.ClearContents Cells(1, 1).Select
Set queryBP = Sheets(temp).QueryTables.Add("ODBC;DSN=Symposium4.0;SRVR=ICCM_PREVIEW;DB=blue;UID=xxxx;PWD=xxxxxx", Sheets(temp).Cells(1, 1), lignequery)
With queryBP .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = True .PreserveFormatting = False .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlOverwriteCells .SavePassword = True .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .PreserveColumnInfo = True .refresh BackgroundQuery:=False End With queryBP.Delete Set queryBP = Nothing Sheets("Agent Summary").Activate End Sub Private Sub Put_Recupererlesdatas2(ByVal temp2 As String, ByVal lignequery2 As String, ByVal ligne2 As Integer, ByVal colonne2 As Integer) Dim queryBP2 As QueryTable ThisWorkbook.Activate Sheets(temp2).Activate Range(Cells(1, 1), Cells(ligne2, colonne2)).Select 'Selection.ClearContents Cells(1, 1).Select Set queryBP2 = Sheets(temp2).QueryTables.Add("ODBC;DSN=Symposium4.0;SRVR=ICCM_PREVIEW;DB=blue;UID=xxx;PWD=xxx", Sheets(temp2).Cells(1, 1), lignequery2) With queryBP2 .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = True .PreserveFormatting = False .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlOverwriteCells .SavePassword = True .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .PreserveColumnInfo = True .refresh BackgroundQuery:=False End With On Error Resume Next queryBP2.Delete Set queryBP2 = Nothing Sheets("Agent Summary").Activate End Sub
Could you please help me as I get angry on the refresh backgroundquery :-)!
|
|
Answer : Getting ODBC general error on command refresh background query
|
|
You can know what was the ODBC error with the fallowing statement:
Excel.Application.ODBCErrors.Item(1).ErrorString
Use this version of your code for find the ODBC Error.
Sub RefreshQueryBPline() On Error GoTo err_Label
Dim lignequery As String, lignequery2 As String, tdebut As String, tfin As String tdebut = Format$(Now, "yyyy-mm-dd") + " 07:45:00" tfin = Format$(Now, "yyyy-mm-dd") + " 18:15:00" lignequery = "SELECT iAgentPerformanceStat.Timestamp, iAgentPerformanceStat.AgentLogin, iAgentPerformanceStat.SupervisorLogin, iAgentPerformanceStat.AgentSurName, iAgentPerformanceStat.CallsAnswered, iAgentPerformanceStat.TalkTime, iAgentPerformanceStat.HoldTime, iAgentPerformanceStat.LoggedInTime, iAgentPerformanceStat.NotReadyTime, iAgentPerformanceStat.DNOutExtCalls, iAgentPerformanceStat.DNOutExtCallsTalkTime, iAgentPerformanceStat.CallsReturnedToQ, iAgentPerformanceStat.ShortCallsAnswered , iAgentPerformanceStat.CDNCallsTransferredToCDN FROM blue.dbo.iAgentPerformanceStat iAgentPerformanceStat WHERE (iAgentPerformanceStat.SupervisorLogin='1120') OR (iAgentPerformanceStat.SupervisorLogin='5140') AND (iApplicationStat.Timestamp>={ts '" + tdebut + "'} And iApplicationStat.Timestamp<{ts '" + tfin + "'}) ORDER BY iAgentPerformanceStat.Timestamp" lignequery2 = "SELECT Agent.TelsetLoginID, Agent.SurName, Agent.GivenName, Agent.Department FROM blue.dbo.Agent Agent WHERE (iApplicationStat.Timestamp>={ts '" + tdebut + "'} And iApplicationStat.Timestamp<{ts '" + tfin + "'}) AND (Agent.Department='Compaq Commercial Products FR') OR (Agent.Department='Compaq Commercial Products NL')ORDER BY Agent.Department, Agent.SurName" Put_Recupererlesdatas "Q_Agent Summary", lignequery, 250&, 16 Put_Recupererlesdatas2 "Q_Case Handling Time", lignequery2, 9000&, 5
err_Label: MsgBox Excel.Application.ODBCErrors.Item(1).ErrorString
End Sub
|
|
|
|