I have a query where the SQL is generated by the choices made on a form. The query is then ran for the user to view. Currently I use something like the following (SQL statement and name vary)
Dim db As DAO.Database
Dim qd As DAO.QueryDef
Dim SQL As String
Set db = CurrentDb
SQL = "SELECT * from [QueryAccounts] "
strName = "AccountDetail"
Set qdf = db.CreateQueryDef(strName, SQL)
DoCmd.DeleteObject acQuery, strName
The last line does not work because the query is open. These are not queries that I want cluttering up the database unless the user chooses to save them. How can I open the query for them to view without saving it in the database?
The deleting it in the unload idea will only work if the user has closed the query before closing the form, which isn't usually the case since the query is designed to be used, the form is designed to create the query.
The idea of not naming the query sounded great but I couldn't get it to work. I was able to set the querydef without a name but then I didn't have a name available for opening the query with, which is the whole point of the form.