Results 1 to 6 of 6
  1. #1
    SusanCoder is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Mar 2016
    Posts
    30

    Refresh or requery subfrm from the AfterUpdate event of another subform's field

    Thanks for your help with the syntax for a refresh or requery a subfrm after a separate subform field has been updated. I tried the following code without success.

    Code:
     Private Sub Amount_AfterUpdate()
              Me.[OKIL Main Screen]!subfrmFundOneTimeDriverEd.Form.Requery
    End Sub
    Run-time error ‘2465’: Microsoft Access can’t find the field ‘|1’ referred to in your expression.

    master form name = OKIL Main Screen (Inherited name, did not name! lol)
    2 child subforms' names = FundsSubTable (again, did not name) and subfrmFundOneTimeDriverEd.

    The subforms each have a master/child relationship with the master form through the UniqueID field (client’s UniqueID).



    Subform FundsSubTable records funds requests for a client (UniqueID) by DateOfService, Code, Amount.
    SubfrmFundOneTimeDriverEd's shows the results for the client (UniqueID) of the sum of Amount for each Code.

    In the After Update event for FundsSubTable.Code, I want to re-run the query (or refresh the form) for subfrmFundOneTimeDriverEd, so that the sums are updated after a user makes a change to the FundsSubTable.Amount.

    Thanks, again, for assistance.

  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    http://www.techrepublic.com/blog/mic...ubform-107106/

    You're referencing the subforms wrongly


    Sent from my iPhone using Tapatalk

  3. #3
    SusanCoder is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Mar 2016
    Posts
    30
    Thanks, andy49.

    I took your advice and changed the syntax suggested by the article from your link. I didn't get an error message, but changing the amount didn't change the sum in the other subform.

    Forms!mainform.Form.subform.controlonsubform

    [code]Private Sub Amount_AfterUpdate()
    Forms![OKIL Main Screen].Form.subfrmFundOneTimeDriverEd.Requery
    End Sub [/code]

  4. #4
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    SusanCoder,

    You are using the after update event of a control which fires BEFORE the record has been saved. The change is still in the " record buffer". You must save the record before other forms can see the change to the record.

    I would use the form's After update event to requery other forms.


    Code:
    Private Sub Amount_AfterUpdate() 
    
         Me.Dirty = False ' save the record
    
    End Sub

    In the form's After Update event

    Code:
    Private Sub Form_AfterUpdate() 
    
    ' now the record has been saved, update the sub form
       Forms![OKIL Main Screen].Form.subfrmFundOneTimeDriverEd.Requery
    
    
    End Sub

  5. #5
    SusanCoder is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Mar 2016
    Posts
    30
    HiTechCoach, you are a rock star. Your solution worked! I appreciate your explanation along with the code because it helped me learn. Can't thank you enough.

    For future reference for those looking at this solution: I added Me.Dirty=False to the AfterUpdate event on the Amount control in the form FundsSubTable, and added the requery statement Forms![OKIL Main Screen].Form.subfrmFundOneTimeDriverEd.Requery to the form FundsSubTable's AfterUpdate event.
    Last edited by SusanCoder; 03-14-2017 at 02:00 PM.

  6. #6
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    You're welcome. Glad we could assist.

    And thank you for "paying it forward" by sharing your solution so other may benefit.

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

Similar Threads

  1. Field Change to requery/refresh subform!
    By DubCap01 in forum Forms
    Replies: 3
    Last Post: 01-07-2015, 10:13 PM
  2. Replies: 11
    Last Post: 09-17-2012, 02:23 PM
  3. Replies: 2
    Last Post: 06-09-2012, 01:56 AM
  4. Refresh Requery Subform
    By eww in forum Programming
    Replies: 1
    Last Post: 04-05-2011, 09:19 AM
  5. AfterUpdate event won't refresh subform!
    By Remster in forum Forms
    Replies: 16
    Last Post: 11-26-2010, 10:06 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