Я думаю, что вы хотите:
If Not IsNull(DLookup("Type", "MSYSObjects", "Name='MyNewQuery'")) Then
MsgBox "An object already exists with this name"
Else
CurrentDb.CreateQueryDef "MyNewQuery", "SELECT * FROM Table1"
End If
Редактировать комментарии
Sub UpdateQuery(QueryName, SQL)
''Using a query name and sql string, if the query does not exist, ...
If IsNull(DLookup("Name", "MsysObjects", "Name='" & QueryName & "'")) Then
''create it, ...
CurrentDb.CreateQueryDef QueryName, SQL
Else
''Other wise, update the sql.
CurrentDb.QueryDefs(QueryName).SQL = SQL
End If
End Sub
Обратите внимание, что удаление несуществующего запроса приведет к ошибке.
DoCmd.DeleteObject acQuery, "NewQuery"