Hi,
Please help me!
I writed SQL query in VBA excel with use ODBC connection and Database Access. My database table have 4 tables ,if i writed query use only one table i have result ,but 2 tables joined and use writed query doesn't work it. Please explain me! I showed code following and attached example tables .doc file(ComputerShop).
[vba]Sub query1()
Sheets.Add
ActiveSheet.Name = n & "-SQL1"
sSQL = "SELECT Product.ID_Prod, Product.Model, Product.Country,Laptop.Model,Laptop.Types, Laptop.Price" _
& "FROM Product, Laptop " _
& "WHERE Product.Model=Laptop.Model AND price< 500" _
ActiveCell.Range("C1") = sSQL
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=ComputerShop;DBQ=H:\VBA\SQL\ComputerShop"), _
Array("\ComputerShop.mdb;DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;")), _
Destination:=Range("A4"))
.CommandText = Array(sSQL)
.Name = "SQL From ComputerShop"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub
[/vba]
Very Thanks!