Jaymond Flurrie
Well-known Member
- Joined
- Sep 22, 2008
- Messages
- 921
- Office Version
- 365
- Platform
- Windows
I'm trying to query one Excel Workbook, two separate places to join them.
Here's the source book, the name of the worksheet is Sheet:
And here's the code. Note that I have a simpler query there that doesn't give me any errors, just to prove the problem is somehow with the join. The one with join gives run-time error -2147217900 (80040e14) with message "Syntax error in FROM clause".
My Excel version is actually 16.0, but that 12.0 seems to work better (well, excluding this join) for some reason. Using 16.0 in connection properties gives "Could not find installable ISAM", but let's not concentrate on this version part unless it is really mandatory for the join to work. I just want the join to work, the rest doesn't really matter right now.
Here's the source book, the name of the worksheet is Sheet:
And here's the code. Note that I have a simpler query there that doesn't give me any errors, just to prove the problem is somehow with the join. The one with join gives run-time error -2147217900 (80040e14) with message "Syntax error in FROM clause".
VBA Code:
Sub JoinTest()
'Here's the SQL I'm trying to perform
'SELECT o.OneValue
'FROM One o
'JOIN Two t
'ON o.OneID = t.TwoID
Dim connection As Object
Set connection = CreateObject("ADODB.Connection")
With connection
.Provider = "Microsoft.ACE.OLEDB.12.0"
.ConnectionString = "Data Source=" & ThisWorkbook.FullName & ";" & _
"Extended Properties=""Excel 12.0 Xml;HDR=Yes"";"
.Open
End With
Dim workingsql As String
workingsql = "SELECT o.OneValue " & _
" FROM [Sheet$A1:B4] o "
Dim workingresult As Object
Set workingresult = connection.Execute(workingsql)
Dim nonworkingsql As String
nonworkingsql = "SELECT o.OneValue " & _
" FROM [Sheet$A1:B4] o " & _
" JOIN [Sheet$E1:G5] t " & _
" ON o.OneID = t.TwoID"
Dim nonworkingresult As Object
Set nonworkingresult = connection.Execute(nonworkingsql)
'And then whatever handling logic here, I just want that join to work to begin with
End Sub
My Excel version is actually 16.0, but that 12.0 seems to work better (well, excluding this join) for some reason. Using 16.0 in connection properties gives "Could not find installable ISAM", but let's not concentrate on this version part unless it is really mandatory for the join to work. I just want the join to work, the rest doesn't really matter right now.