Results 1 to 3 of 3
  1. #1
    Crdmster is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Mar 2017
    Posts
    13

    SubForm Refreshing After Table Updates

    Attached is a rough example of the problem I can't seem to overcome throughout my database. All help and/or advice is greatly appreciated. In essence, I'm not able to determine a repeatable way to refresh the Form/SubForm after adding a value to atable via VBA. I've tried different Form refresh methods, Me.Refresh methods, and also tried closing all forms and reopening (all within the VBA code). Using Me.Refresh works some of the times, but I believe lag in the system occasionally makes it so the refresh does not work. I've found that I can add a "Pause" in the code before refreshing and that resolves the problem, but that's not an efficient solution since I would have to tell the system to wait up to 10 seconds each time a button edits a table.



    The "Refresh All" button on Access top ribbon works perfectly, but I can't expect users to click that button each time a change has been implement.

    Issue:
    After adding a new comment to tblComments via the "Add New Comment" button, the data is added to the appropriate table and query, but I can't find a reliable way to refresh/requery/repaint the subForm.

    Question:
    What are the recommended methods to adding values to tables and instantaneously updating the query in the subform.


    Condensed Code Used to Insert New Comments to Table:
    Code:
     
    strTable= "tblComments"
    strFields="[ProjectName], [Date], [UserName], [Comment]"
    strValues=""XXX", "6/1/2022" , "XXX", "Test Comment"
    strSQL = "INSERT INTO " & strTable & " (" & strFields & ") VALUES (" & strValues & ");"
    DoCmd.RunSQL strSQL

    Database Example.pdf

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,811
    Refresh in vba updates current recordset - it does not load new records, nor does it remove deleted ones from view. Use Requery for that.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,118
    I agree that Requery of the subform would work:
    Code:
    Me.frmSubComments.Form.Requery
    But that will reposition the record to the first record of the subform (which might not be a problem for you as you seem to have the subform as a datasheet or continuous form). But if you need to stay on the same record you can try to requery the recordset of the subform:
    Code:
    Me.frmSubComments.Form.Recordset.Requery
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Refreshing subform
    By dotcanada in forum Access
    Replies: 8
    Last Post: 08-11-2016, 07:37 AM
  2. Replies: 6
    Last Post: 11-30-2013, 02:41 PM
  3. Refreshing a subform
    By RobRoy in forum Forms
    Replies: 8
    Last Post: 07-22-2013, 04:19 PM
  4. SubForm not refreshing
    By hawkins in forum Access
    Replies: 2
    Last Post: 08-16-2011, 04:30 PM
  5. Refreshing a subform?
    By Shag84 in forum Forms
    Replies: 4
    Last Post: 08-07-2011, 10:07 AM

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