Hello Everybody!
I'm trying to get collect data from two excel sheet with OLEDB and sql query with subquery but couldnt.
I got error messaage:
At most one record can be returned by this subquery (Run-time error :80004005)
Please help me, I was trying to find solution on internet but couldnt.
I'm trying to get collect data from two excel sheet with OLEDB and sql query with subquery but couldnt.
I got error messaage:
At most one record can be returned by this subquery (Run-time error :80004005)
Please help me, I was trying to find solution on internet but couldnt.
Rich (BB code):
Sub Makró1()
'
' Makró1 Makró
'
Dim myConnection As String
Dim RS As ADODB.Recordset
Dim mySQL As String
Dim strPath As String
Dim wsMain As Worksheet
Debug.Print Now
Set wsMain = Worksheets("Report")
Application.ScreenUpdating = False
strPath = ActiveWorkbook.FullName
myConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & strPath & ";Extended Properties=Excel 12.0"
mySQL = "SELECT [T2$].[A], " & _
"[T2$].[B1], " & _
"[T1$]., " & _
"(select SUM([T2$].[B1]) FROM [T2$] GROUP BY [T2$].[A], [T2$].[B1]) " & _
"FROM [T2$] inner JOIN [T1$] ON [T2$].[A] = [T1$].[A] where [t1$]. <> 0"
Set RS = New ADODB.Recordset
RS.Open mySQL, myConnection, adOpenForwardOnly, adLockOptimistic
wsMain.Range("A2").CopyFromRecordset RS
RS.Close
Set RS = Nothing
Application.ScreenUpdating = True
Debug.Print Now
'
End Sub
Last edited by a moderator: