CreateQueryDef Method Example

This example creates a QueryDef named "All Pubs" with an SQL statement, and then creates a Dynaset based on the query.

Dim MyDB As Database, MyQuery As QueryDef, MySet As Dynaset
Set MyDB = OpenDatabase("BIBLIO.MDB")       ' Open a database.
' Create a QueryDef.
Set MyQuery = MyDB.CreateQueryDef("All Pubs", "SELECT * FROM Publishers;")
Set MySet = MyDB.CreateDynaset("All Pubs")  ' Create dynaset from query.
MyQuery.Close                               ' Close QueryDef object.
MyDB.DeleteQueryDef("All Pubs")             ' Delete QueryDef.