I want to run the sql queries via VBA excel below are my code which is successfully run for me for two table inner join.
Now I want to edit the query in which i can combined more the 2 tables with the help of Inner join.
Sub SQL()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
strFile = ThisWorkbook.FullName
strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFile _
& ";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=1"";"
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cn.Open strCon
strSQL = "SELECT [Sheet2$].[Sr], [Code], [Family] FROM [Sheet3$] INNER JOIN [Sheet2$] ON [Sheet2$].[Sr]=[Sheet3$].[Sr]"
''Here i want to edit the code to combined more the 2 tables with the help of Inner join.
rs.Open strSQL, cn
Sheet3.Range("D1").CopyFromRecordset rs
End Sub
for example:- I have one more table in sheet 4 in which also the Sr header is available.Please guide me for the same.
