Example of using Visual Basic to change a query's SQL statement
You can use the SQL property of a QueryDef object to change the underlying SQL statement of a query. For example, the following block of Microsoft Visual Basic code changes the underlying SQL statement of the query Employee List so that the query selects all records in the Employees table:
Dim dbsCurrent As Database
Dim qryTest As QueryDef
Set dbsCurrent = CurrentDb
Set qryTest = dbsCurrent.QueryDefs("Employee List")
qryTest.SQL = "SELECT * FROM Employees;"