即効テクニック |
サンプルでは、Jetワークスペースオブジェクトを使い、開かれていない別のデータベースのRecordsetオブジェクトを作成して、レコードの内容をイミディエイトウィンドウに出力しています。 Sub Sample() Dim myPath As String Dim wsp As Workspace Dim db As Database Dim rec As Recordset 'Jep Workspaceオブジェクト作成 Set wsp = CreateWorkspace("", "admin", "", dbUseJet) myPath = "C:\大村\Mougテクニック集\Access\VBA\" '排他モードで Database オブジェクト作成 Set db = wsp.OpenDatabase(myPath & "東京", True) Set rec = db.OpenRecordset("在庫", dbOpenTable) Debug.Print rec!商品番号 & ":" & rec!商品名 rec.Close db.Close wsp.Close End Sub OpenDatabaseメソッドは、Workspaceオブジェクトで指定したデータベースを開き、そのデータベースを表すDatabaseオブジェクトへの参照を返します。