Neil,
here's some code:
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Set db = CurrentDb
'Put together the query as needed
'(see also the SQL view of saved queries)
strSQL = "SELECT * FROM MyTable"
'Create the new query
'If you want to save the query
'so that it will show up in the database window,
'you need to specify the name:
Set qdf = db.CreateQueryDef("MyQuery", strSQL)
'If you want a temporary query
'not saved in the DB, pass a nullstring as
'the name
Set qdf = db.CreateQueryDef("", strSQL)
Set db = Nothing
Please note: if there is already a query with the given name, there'll
be an error. See also Help item CreateQueryDef method and the
examples.
Best regards
Emilia
Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de