I have a form with a button. When I click on the button I want to update the Sql in that query to something else - in a similar way to updating a form's recordsource I guess?
As an example I want to update the Query "MyQuery" with "SELECT * from CUSTOMERS". How would I do this? I was playing around with the following but it doesn't work so...
Code:
Dim NewSQL As QueryDef
Set NewSQL = CreateQueryDef("SELECT * from CUSTOMERS",MyQuery)
Dim db As Database
Dim qdf As QueryDef
Dim strSQL As String
Set db = CurrentDb
strSQL = "SELECT * FROM CUSTOMERS;"
db.QueryDefs("MyQuery").SQL = strSQL
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Set db = CurrentDb
Set qdf = db.QueryDefs("MyQuery")
qdf.SQL = "SELECT * from CUSTOMERS"
qdf.close
Set db = Nothing
Set qdf = Nothing