Name

querytable.Recordset[= setting]

Synopsis

Sets or returns a Recordset object that serves as the data source for the specified query table. The following code creates a query table using the Employees table in the Northwind Traders sample database as the recordset and inserts the name of the recordset as well as the recordset data in the active worksheet:

Dim strDbPath As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim qt As QueryTable
 
strDbPath = "C:\Program Files\Microsoft Office\" & _
    "OFFICE11\SAMPLES\Northwind.mdb"
 
Set db = OpenDatabase(strDbPath)
Set rs = db.OpenRecordset("Employees")
 
Set qt = ActiveSheet.QueryTables.Add(Connection:=rs, _
    Destination:=ActiveSheet.Range("A3"))
 
ActiveSheet.Range("A1") = qt.Recordset.Name & " table:"
 
qt.Refresh

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.