Results 1 to 4 of 4

Thread: dao open query

  1. #1
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264

    Question Unanswered: dao open query

    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)

    Code:
    	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.OpenQuery strName
    	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?

    Thanks.

    Steve

  2. #2
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    What you can do, just delete the query in the Unload event of the Form

  3. #3
    Join Date
    Jul 2004
    Posts
    34
    The easiest solution (and let's be honest therefore the best ) is to just not give the QueryDef a name, and hence it isn't saved once closed!

  4. #4
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264
    Thank you both for your ideas.

    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.

    Any other thoughts?

    Steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •