Взято из MSDN
HOWTO: Access Multiple Databases in an SQL Query in VB 3.0
ID:
Q113701
Code Example of a Multiple Database Query
This example creates a dynaset joining two tables from two data sources, one an SQL Server and the other a Microsoft Access database. The TestTab table is on the SQL Server and the T1 table is in the Microsoft Access database.
Dim db As database
Dim ds As dynaset
Dim sql As String, Uid$, Pwd$
Set db = OpenDatabase("C:\VB\BIBLIO.MDB")
' This obtains a valid database object. It does not have to be a Microsoft
' Access database; the following works equally as well:
' Set db = OpenDatabase("C:\FOXPRO25\", 0, 0, "foxpro 2.5")
' The values here are hard-coded, but you could prompt the user for their
' user id and password.
Uid$ = "sa"
Pwd$ = ""
' Build the select statement, concatenating the user's id and password:
sql = "SELECT T1.F2, TestTab.F2, TestTab.F3"
sql = sql & " FROM [;database=C:\ACCESS\DB1.MDB].T1 , "
sql = sql & " [odbc;dsn=texas;database=playpen;uid=" & Uid$
sql = sql & ";pwd=" & Pwd$ & "].TestTab"
sql = sql & " WHERE T1.F1 = TestTab.F1"
' Execute the select query:
Set ds = db.CreateDynaset(sql)
' Loop through and display the records:
While Not ds.EOF
For i = 0 To ds.Fields.Count — 1
Print ds(i); " ";
Next i
Print
ds.MoveNext
Wend