Microsoft.ACE.OLEDB.12.0 Not working

jimbojimbo

New Member
Joined
Sep 5, 2012
Messages
3
Hi,

I am trying to query some data in an excel sheet using the Micosoft.ACE.OLEDB.12.0 it works fine when there are less than 65536 rows of data, however, when there is more than this it bugs out saying that it cant find the object. Any ideas how to get this to work for large data sets. I am using excel 2010

Public Sub GetData(SourceFile As Variant, SourceSheet As String, _
sourceRange As String, TargetRange As Range, HeaderRow As Boolean)
Dim rsData, rsData1, rsData2, rsData3, rsData4, rsData5, rsData6, rsdata7, rsdata8, rsdata9, rsdata10, rsdata11 As ADODB.Recordset
Dim szConnect As String
Dim szSQL, szSQL1, szSQL2, szSQL3, szSQL4, szSQL5, szSQL6, szSQL7, szSQL8, szSQL9, szSQL10, szSQL11 As String
Dim lCount As Long
Dim rscon As ADODB.Connection

szConnect = "Provider=Microsoft.Ace.OLEDB.12.0;" & "Data Source=" & SourceFile & ";" & "Extended Properties=""Excel 12.0;HDR=Yes"";"

szSQL = "SELECT top 5 [Country],[admin1name], sum([TIV ($USD)]) as 'TIV' FROM [" & SourceSheet$ & "$" & sourceRange$ & "] where[Peril] = 'Earthquake' Group by [Country],[admin1name] ORDER BY SUM([TIV ($USD)]) desc ;"
Set rscon = New ADODB.Connection
rscon.Open szConnect
Set rsData = New ADODB.Recordset
rsData.Open szSQL, rscon, adOpenForwardOnly, adLockReadOnly, adCmdText

' Check to make sure we received data and copy the data
If Not rsData.EOF Then

'Add the header cell in each column if the last argument is True
If HeaderRow Then
For lCount = 0 To rsData.Fields.Count - 1
TargetRange.Cells(1, 1 + lCount).Value = _
rsData.Fields(lCount).Name
Next lCount
TargetRange.Cells(6, 1).CopyFromRecordset rsData
Else
TargetRange.Cells(6, 1).CopyFromRecordset rsData
End If


Else
MsgBox "No records returned from : " & SourceFile, vbCritical
End If
' Clean up our Recordset object.
rsData.Close
Set rsData = Nothing
rscon.Close
Set rscon = Nothing

[/PHP]
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
If I remember rightly, this works if you don't specify a range but just use a sheet name?
 
Upvote 0
Thanks for the reply, but that doesnt seem to work either. Have now changed it to the below:

szSQL = "SELECT top 5 [Country],[admin1name], sum([TIV ($USD)]) as 'TIV' FROM [" & SourceSheet & "] where[Peril] = 'Earthquake' Group by [Country],[admin1name] ORDER BY SUM([TIV ($USD)]) desc ;"

The error message i get is "The microsoft access database engine could not find the object 'Test'. Make sure the object exists...."
 
Upvote 0
Try this, there needs to be a $ sign after sheet name

Code:
szSQL = "SELECT top 5 [Country],[admin1name], sum([TIV ($USD)]) as 'TIV' FROM [" & SourceSheet & "$] where[Peril] = 'Earthquake' Group by [Country],[admin1name] ORDER BY SUM([TIV ($USD)]) desc ;"
 
Upvote 0

Forum statistics

Threads
1,215,643
Messages
6,125,990
Members
449,278
Latest member
MOMOBI

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top