Results 1 to 4 of 4
  1. #1
    The Professor is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Location
    Cambridgeshire, UK
    Posts
    67

    Updating a QueryDef

    Hi,



    I have a predefined query that a combo box uses for its Row Source, and it works - after a fashion.

    The problem is that the criteria in one of the columns in the QueryDef is a value in a Control on a Form. However as that values changes (as the records change), the query is not updating to reflect that, so I need a way in code, to "refresh" or "requery" the query, before the Combo Box displays the results in its Drop Down list.

    If I run the Query myself as a user so that it displays the results in a Datasheet, it works fine and displays the correct data each time. However the Combo Box results are only correct the first time it is used, after that that drop down list always displays that same data it did first time, whatever the value of the Criteria Field in the Query.

    I have had a stab at trying to update this query before the Combo Box is used, but I keep running into problems, the latest one being the "Error 3065, cannot execute a Select Query". I think I could use some help/guidance with this.

    Prof.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    It sounds like you are trying to do something like

    db.execute strMySQL

    you can not execute a select query.
    Execute works for action queries (Add(Insert), Modify(Update), Delete(Delete))

    It also sounds like you need to "refresh" your query in the Afterupdate event of the combo.

    Eg:
    Select a value in the combo, requery the combo to refresh the form so the query has proper value, then run the query.

    Perhaps you could show us some code, since I'm assuming a lot from your post.
    Last edited by orange; 08-05-2014 at 07:32 AM. Reason: edited after seeing John_G requery. I modified this post to remove the "refresh" and deal with the requery of combo in afterU

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi

    Try requerying the combo box in the On Current event of the form. If you manually change the value in the form control the query uses, Requery the combo box in the After Update event of that form control too.

    The syntax is : Me![comboboxname].Requery

    HTH

    John

  4. #4
    The Professor is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Location
    Cambridgeshire, UK
    Posts
    67
    Hi,

    Thanks for the replies.

    >>It sounds like you are trying to do something like
    >>db.execute strMySQL


    Yes, Orange, that is what I was trying, and of course it didn't work, but it did result in some interesting bedtime reading about differences between Action queries, Select queries, Parameter queries etc. as I brushed up on chapter 5 of my copy of "Access Inside Out".

    John_G, thanks for the example of Me![comboboxname].Requery it did the trick! Great - job done, thanks!

    Prof.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Reading fields in querydef - how to find criteria
    By aytee111 in forum Programming
    Replies: 4
    Last Post: 05-08-2014, 03:44 PM
  2. QueryDef
    By crowegreg in forum Programming
    Replies: 2
    Last Post: 09-18-2012, 09:31 AM
  3. Can someone explain querydef?
    By roguex20 in forum Access
    Replies: 2
    Last Post: 07-22-2012, 11:57 AM
  4. Exporting to Excel with Automation using QueryDef
    By Niezels in forum Import/Export Data
    Replies: 3
    Last Post: 09-26-2010, 05:55 PM
  5. Adding Totals to a query using queryDef
    By jrickels in forum Programming
    Replies: 7
    Last Post: 04-06-2010, 07:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums