I am writing an SQL statement to generate a query and then open a report:
' Run the query and report
MyDB.QueryDefs.Delete "qryCustom"
Set qdf = MyDB.CreateQueryDef("qryCustom", strSQL)
DoCmd.OpenReport "rptCustom", acPreview
my SQL statement ends with an ORDER BY statement...