First just create a query object so that you can manipulate the SQL. Then you can open the querydef in code and update the SQL Statement. Something like below would work or at least give you and idea
Dim def As QueryDef
Set def = CurrentDb.QueryDefs("queryName")
def.SQL = "SQLstring"