April 2006
Beginner
1114 pages
98h 16m
English
querytable.Connection[= setting]
Sets or returns the connection string for the specified query table. The following code creates a query table, returns its results, and displays the connection string in cell A6:
Dim strConn As String
Dim strSQL As String
Dim qt As QueryTable
strConn = "ODBC;DSN=MS Access Database;" & _
"DBQ=C:\Program Files\Microsoft Office\OFFICE11\SAMPLES\Northwind.mdb;"
Set qt = ActiveSheet.QueryTables.Add(Connection:=strConn, _
Destination:=ActiveSheet.Range("A1"))
qt.CommandText = "SELECT * FROM Products WHERE (Products.ProductID=10)"
qt.Refresh
ActiveSheet.Range("A6") = qt.ConnectionRead now
Unlock full access