bs0d
Well-known Member
- Joined
- Dec 29, 2006
- Messages
- 622
I'm running an ADO query through Excel to insert up to 50k rows into a table. The query uses dSUM to get a running total for items by date, so it's likely that it is "calculation heavy". Even running directly in Access, it takes a moment to complete.
When running it in Excel however, I get the subject runtime error after exactly 10,051 records have been inserted.
What can I do in this situation? Here is my code:
When running it in Excel however, I get the subject runtime error after exactly 10,051 records have been inserted.
What can I do in this situation? Here is my code:
Code:
sSQL = "INSERT INTO tmp_CUMS_by_Date ([item_KEY], [ReadingDate], [CUM1], [CUM2], [CUM3], [Username]) " _
& "SELECT [item_KEY], [ReadingDate], " _
& "DSum('value1','tblDailyReadings','[iteml_KEY]=' & [item_KEY] & ' And [ReadingDate]<=#' & [ReadingDate] & '#') AS CUM1, " _
& "DSum('value2','tblDailyReadings','[item_KEY]=' & [item_KEY] & ' And [ReadingDate]<=#' & [ReadingDate] & '#') AS CUM2, " _
& "DSum('value3','tblDailyReadings','[item_KEY]=' & [item_KEY] & ' And [ReadingDate]<=#' & [ReadingDate] & '#') AS CUM3, " _
& "'" & Module1.UserNameWindows() & "' AS [Username] " _
& "FROM [tblDailyReadings] INNER JOIN [tblItemInfo] ON [tblDailyReadings].[item_KEY] = [tblItemInfo].[item_IDX] " _
& "GROUP BY [item_KEY], [ReadingDate], [" & db_field & "]" _
& "HAVING ((([" & db_field & "]) =" & Chr(34) & ActiveSheet.cboGroupFieldList.Value & Chr(34) & " )) " _
& "ORDER BY [ReadingDate];"
Set myConnection = New ADODB.Connection
FilePath = "L:\db\history.accdb"
'Proceed with INSERT:
With myConnection
.Provider = "Microsoft.ACE.OLEDB.12.0"
.Open "Data Source = """ & FilePath & """"
.Execute sSQL, adExecuteNoRecords
End With
'Close connection
If CBool(myConnection.State And adStateOpen) = True Then
myConnection.Close
Set myConnection = Nothing
End If
Last edited: