>
Dim dbsNorthwind As Database, qdfPassThrough As QueryDef
Set dbsNorthwind = DBEngine.Workspaces(0).OpenDatabase("Northwind.mdb")
Set qdfPassThrough = dbsNorthwind.CreateQueryDef("October " & _
"Orders","SELECT * From Orders WHERE ShipCity = 'London'")
dbsNorthwind.Connect = "ODBC; DSN=MySQLDBDSN; " _
& " UID=Chrissy;PWD=FourOh;"
qdfPassThrough.ReturnsRecords = True
Example (Microsoft Access)
The following example creates an SQL pass-through query that returns records from an external database.
Sub CreatePassThrough()
Dim dbs As Database, qdfPassThrough As QueryDef
' Return Database variable that points to current database.
Set dbs = CurrentDb
Set qdfPassThrough = dbs.CreateQueryDef("OctoberOrders", _
"SELECT * From Orders WHERE ShipCity = 'London'")
dbs.Connect = "ODBC; DSN=MySQLDBDSN; " _
& " UID=Chrissy;PWD=FourOh;"
qdfPassThrough.ReturnsRecords = True
End Sub