SQL Property Example

The example creates a blank QueryDef, then sets the SQL property and creates a Snapshot based on the query.  The query selects all Titles published after 1988, and prints the Title and Year Published in the Debug window.

Dim MyDB As Database, MyQuery As QueryDef, MySnapshot As Snapshot
Set MyDB = OpenDatabase("BIBLIO.MDB")
' Save query in the database.
Set MyQuery = MyDB.CreateQueryDef("New TitlesA")
MyQuery.SQL = "SELECT * FROM Titles WHERE [Year Published] > 1988;"
Set MySnapshot = MyQuery.CreateSnapshot()   ' Create Snapshot.
Do While Not EOF
  Debug.Print MySnapshot.Fields("Title"),
  Debug.Print MySnapShot.Fields("Year Published")
  MySnapShot.MoveNext
Loop