Results 1 to 4 of 4
  1. #1
    Sinca is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    2

    Access2016, subfoem.requery did not work, help!

    Access2016, subform.requery did not work. subform based on query2 and query2 based on query1. I changed SQL text of query1 in VBA and want subform.requery to reflect the changes. The code goes as below:
    Code:
    dim db as database
    dim qry as querydef
    set db=currentdb
    set qry=db.querydefs("query1")
    
    qry.SQL=some string
    me.subform1.form.requery
    --------------------------------------
    result:


    1-sub form did not reflect changes.
    2-I checked query1 and query2, they work properly.
    3-if I close form and reopen it, it works! reflect all changes as I expected.

    I can provide database file for details.
    Please help. Thanks a lot!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    .form reference does not work because the form is not open as a form - it is an object held by a subform container, not a member of the open forms collection. Reference the subform container control, not the form in the container.

    Recommend naming container different from the object it holds, like ctrDetails: Me.ctrDetails.Requery

    Why are you changing query? This is modifying db design.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Sinca is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    2
    Thank you for your help!
    1-I tried renamed subform container as ctrDetails and use Me.ctrDetails.Requery, also did not work.
    2-changing query is for passing combobox data in mainform to query parameters. So user can get the results he want based on his choice on combobox.
    Now I am thinking after changing query1.SQL, still missing some action to do before ctrDetails.Requery so that passing the new SQL to subform.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    The requery method works for me, so yes, something else must be necessary.

    If this query is the source for a form RecordSource then why don't you just apply filter criteria to form?

    I have only ever once resorted to using QueryDefs to modify query and I was kicking and screaming the whole time. The query was not source for RecordSource, it was used to export data to Excel.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. AfterUpdate requery does not requery list box
    By ittechguy in forum Programming
    Replies: 5
    Last Post: 09-05-2017, 08:51 AM
  2. Replies: 4
    Last Post: 12-06-2014, 08:49 PM
  3. Requery macro dont work
    By Lubosh97 in forum Macros
    Replies: 2
    Last Post: 05-06-2014, 08:21 AM
  4. How did this requery work?
    By Access_Novice in forum Programming
    Replies: 1
    Last Post: 01-04-2014, 07:30 PM
  5. Replies: 4
    Last Post: 12-31-2012, 01:10 PM

Tags for this Thread

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