Avatar
Board Regular
- Joined
- Sep 20, 2005
- Messages
- 193
Greetings,
I'm getting the following error when trying to run a SQL query in Excel:
The code is:
The generated statement is (It was unreadably long so i broke it into lines):
I was expecting to have missed a quote or formatted the statement incorrectly, but i can't see anything..
I'm getting the following error when trying to run a SQL query in Excel:
Code:
Run-time error '-2147217904 (80040e10)':
[Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect
The code is:
Code:
Sub ExtractFrom_DB_ADO()
Dim Conn As New ADODB.Connection
Dim Rst As New ADODB.Recordset
Dim MySQL As String, _
AccessConnect As String
Dim xlApp As Object, _
xlWb As Object, _
xlWs As Object
Dim recArray As Variant
AccessConnect = "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=" & DBName & ";" & _
"DefaultDir=" & DatabaseDIR & ";" & _
"Uid=Admin;Pwd=" & strPassword & ";"
Conn.Open AccessConnect
MySQL = _
"SELECT tbl_DataReturn.Date, tbl_DataReturn.EmployeeNumber, Sum(tbl_DataReturn.Hours) AS SumOfHours, tbl_HistoricRewardScore.OverallRewardPercent, [tbl_DataReturn].[Hours]*[tbl_HistoricRewardScore].[OverallRewardPercent] AS Reward " & _
"FROM tbl_HistoricRewardScore INNER JOIN tbl_DataReturn ON tbl_HistoricRewardScore.Date = tbl_DataReturn.Date " & _
"GROUP BY tbl_DataReturn.Date, tbl_DataReturn.EmployeeNumber, tbl_HistoricRewardScore.OverallRewardPercent, [tbl_DataReturn].[Hours]*[tbl_HistoricRewardScore].[OverallRewardPercent], tbl_DataReturn.[Deleted?] " & _
"HAVING (((Sum(tbl_DataReturn.Hours)) <> 0) And ((tbl_DataReturn.[Deleted?]) = False)) " & _
"ORDER BY tbl_DataReturn.Date, tbl_DataReturn.EmployeeNumber;"
Set Rst = Conn.Execute(MySQL)
'Sheet3.Cells(3, 2) = MySQL
If Not Rst.EOF Then
Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Add
Set xlWs = xlWb.Worksheets(Sheet3)
xlWs.Cells(3, 2).CopyFromRecordset Rst
'recArray = Rst.GetRows
'I'm still working here
Set xlWs = Nothing
Set xlWb = Nothing
Set xlApp = Nothing
End If
Rst.Close
Conn.Close
Set Rst = Nothing
Set Conn = Nothing
End Sub
The generated statement is (It was unreadably long so i broke it into lines):
Code:
SELECT tbl_DataReturn.Date, tbl_DataReturn.EmployeeNumber, Sum(tbl_DataReturn.Hours) AS SumOfHours, tbl_HistoricRewardScore.OverallRewardPercent, [tbl_DataReturn].[Hours]*[tbl_HistoricRewardScore].[OverallRewardPercent] AS Reward
FROM tbl_HistoricRewardScore INNER JOIN tbl_DataReturn ON tbl_HistoricRewardScore.Date = tbl_DataReturn.Date
GROUP BY tbl_DataReturn.Date, tbl_DataReturn.EmployeeNumber, tbl_HistoricRewardScore.OverallRewardPercent, [tbl_DataReturn].[Hours]*[tbl_HistoricRewardScore].[OverallRewardPercent], tbl_DataReturn.[Deleted?]
HAVING (((Sum(tbl_DataReturn.Hours)) <> 0) And ((tbl_DataReturn.[Deleted?]) = False))
ORDER BY tbl_DataReturn.Date, tbl_DataReturn.EmployeeNumber;
I was expecting to have missed a quote or formatted the statement incorrectly, but i can't see anything..