Create A New Query
acCmdAdvancedFilterSort, acCmdSaveAsQuery
This is an adaptation of some code I found on the comp.databases.ms-access newsgroup posted by Alan Taw. He was trying to create a new query based on a table but it gave me the outline for the following. It does however use Sendkeys and has no error checking.
'***************** Code Start *******************
Sub CreateQuery(strTableName As String, strQueryName As String)
DoCmd.OpenTable strTableName
DoCmd.RunCommand acCmdAdvancedFilterSort
SendKeys "~", False
DoCmd.RunCommand acCmdSaveAsQuery
DoCmd.Close acTable, strTableName
DoCmd.Rename strQueryName, acQuery, "query1"
End Sub
'****************** Code End ********************