In Microsoft Access, a linked table must be opened as the
Recordset object. The following code example assumes that you are linked to the Customers table in the sample database Northwind.mdb, which resides in the same folder as the database containing this code. The code opens the Northwind.mdb file, which actually contains the Customers table. The code then creates a recordset based on the Customers table.
NOTE: The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click
References on the
Tools menu in the Visual Basic Editor, and make sure that the
Microsoft DAO 3.6 Object Library check box is selected.
Public Function testLink()
Dim myDb As DAO.DATABASE, rstCustomers As DAO.Recordset
' Open the Northwind.mdb database.
Set myDb = DBEngine.Workspaces(0).OpenDatabase("Northwind.mdb")
' Create the recordset.
Set rstCustomers = myDb.OpenRecordset("Customers", dbOpenDynaset)
End Function