Results 1 to 9 of 9
  1. #1
    data808 is offline Noob
    Windows 10 Access 2013 32bit
    Join Date
    Aug 2012
    Posts
    727

    Button On A Form To Refresh A Different Form

    How do I write the VBA if I wanted to click on a button in Form1 that will refresh a split form called Form2? I tried this but it's not doing anything:

    [Forms]![Add Edit Users_Query_admin].Form.Refresh

    The form its supposed to refresh is a split form called "Add Edit Users_Query_admin". The refresh button is on a regular form called "Add Edit Users Fetch_admin". This form is modal and basically the user pulls up the record on this form, makes the changes and closes it. When they click the close button, that is where I would like to also refresh the split form so that it shows the update of the record.

  2. #2
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    309
    To refresh a split form called "Form2" when a button is clicked on another form called "Form1", you can use the following VBA code:

    Code:
    Private Sub CommandButton1_Click()
      Forms!Form2.Form.Requery
    End Sub
    This code assumes that the button you want to click is called "CommandButton1" and is located on "Form1". When the button is clicked, the code will refresh the split form called "Form2".

    If you want to refresh the subform within the split form, you can use the following code instead:

    Code:
    Private Sub CommandButton1_Click()
      Forms!Form2.Form!SubformControlName.Form.Requery
    End Sub
    In this case, "SubformControlName" is the name of the subform control on the split form.

    A lot of assumption here, but you should have added more details.

  3. #3
    data808 is offline Noob
    Windows 10 Access 2013 32bit
    Join Date
    Aug 2012
    Posts
    727
    Thanks I added more details above. I guess I should also include that this button is also meant to close the regular form (not split form). So I'm having some issues. Here is the codes I have tried so far:

    DoCmd.Close
    [Forms]![Add Edit Users_Query_admin].Form.Requery

    With the Docmd.Close above the Requery line, it will not refresh the record on the split form if I made an update to the respective record. It will however refresh if I go back into that regular form and click the button again without making any changes. So basically I have to open the form twice. Once for making the update then closing it and then reopen it, don't make any changes and close it and it will refresh the split form to reflect the change to the record.

    Then if I switch the position of the Docmd.Close line to the bottom like this:


    [Forms]![Add Edit Users_Query_admin].Form.Requery
    DoCmd.Close



    It will just close the split form with the regular form remaining open. Then if I click the button again I'll get an error. The regular form is modal btw and it's in front of the split form until the user closes it after making the changes.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,575
    Well if you put the close command before, it close that form, the form that the code is running in? What do you think that will do?
    If you put it after, I would expect it to close the active form?, so it appears the Reuqey code sets the split form as active, so specify which form you want to close?, perhaps using Me.Name ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    data808 is offline Noob
    Windows 10 Access 2013 32bit
    Join Date
    Aug 2012
    Posts
    727
    Split Form = "Add Edit Users_Query_admin"

    Regular Form = "Add Edit Users Fetch_admin"

    Split form opens up and user clicks reference number for the record they want to make the change. I set the reference number (primary key) as a hyper link that they can click on to fetch the record they want and make edits to that record in the
    "Add Edit Users Fetch_admin" form. When the user is done making the change, they save it and click a back button I made which usually just closes this "Add Edit Users Fetch_admin" modal form and sets the focus back to the "Add Edit Users_Query_admin" split form. However, I would like that back button to also requery/refresh the record they made the changes to on the split form so that it shows the change. The only way to do that right now is to close the split form and reopen it. Then the changes will show. So I figured the best place to put some VBA to do this would be that back button on the "Add Edit Users Fetch_admin" form so while its closing, it also requery/refresh the split form to show the changes made to the record.

    What I also noticed is that when it does a requery/refresh, it will also highlight the top record in the split form. The highlight will no longer stay on the record that they just updated. So that is also something I would like to see if we can fix.

    Let me know if you need more information. Thanks for the help.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,575
    Requery the form recordset and not the form.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    data808 is offline Noob
    Windows 10 Access 2013 32bit
    Join Date
    Aug 2012
    Posts
    727
    How do you do that?

  8. #8
    data808 is offline Noob
    Windows 10 Access 2013 32bit
    Join Date
    Aug 2012
    Posts
    727
    Tried this:

    [Forms]![Add Edit Users_Query_admin].Form.Recordset.Requery

    But that didn't do anything.

    Also been reading up on the difference between Requery and Refresh and I think Refresh might be more fitting for this situation. There aren't any new records or deletions and so requery is not necessarily needed. I just need the split form to show the updates made to the record.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,575
    Quote Originally Posted by data808 View Post
    Tried this:

    [Forms]![Add Edit Users_Query_admin].Form.Recordset.Requery

    But that didn't do anything.

    Also been reading up on the difference between Requery and Refresh and I think Refresh might be more fitting for this situation. There aren't any new records or deletions and so requery is not necessarily needed. I just need the split form to show the updates made to the record.
    Well, if another form has updated the data in the background, I would expect you need a requery to obtain that updated data?
    But go ahead and try a refresh.

    No idea as to why your recordset requery did not work. That is a good method to requery without moving to the first record on the form, which the form requery does.
    Another way would be to save the current record as a bookmark, requery the form, then locate the bookmark.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 6
    Last Post: 01-06-2015, 12:37 PM
  2. Replies: 4
    Last Post: 10-09-2014, 07:09 PM
  3. Refresh button in form
    By azhar2006 in forum Forms
    Replies: 5
    Last Post: 03-02-2014, 05:19 PM
  4. Replies: 1
    Last Post: 01-24-2012, 03:47 PM
  5. Replies: 3
    Last Post: 02-14-2011, 02:18 PM

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