Hi ,
Try this out, it worked well when I threw it together. But REMEMBER to read the note in the header... You have been warned... ;)
Public Sub CreateQuery()
'NOTE: this code NEEDS to have a reference to DAO
' If you already have a reference to ADO be sure
' to prefix your variable declarations correctly
' since there are some objects that are the same
' and you will never know which will be opened
' unless you prefix them, i.e.
' Dim ADORecs As ADODB.Recordset
' Dim DAOResc As DAO.Recordset
'
Dim db As DAO.Database
Dim MyQry As DAO.QueryDef
Set db = DBEngine.OpenDatabase("<path to your database")
Set MyQry = db.CreateQueryDef("<Query name>", "<SQL statement>")
db.Close
End Sub
Have fun
Yomet