Share via

Need a Refresh All VBA code that works exactly like the one on the ribbon menu.

Anonymous
2012-11-28T03:36:37+00:00

I'm using MSAccess 2010 and need a referesh all VBA code that works exactly like the one on the ribbon menu.

There are so many answers from other forums but they don't work like I'd expect it to.

My "search form" has a search combo box field that will display the selected record.  - nothing new.

This form will call out the searched record and open another "update form" to allow the user to udate i.e. create a new entry for the existing record.

When I return to the "Seach form" - the data doesn't show up unless I click on the ribbon menu's "Refresh All" button.

Anyone with a reliable VBA code?

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

30 answers

Sort by: Most helpful
  1. Anonymous
    2012-11-28T14:44:31+00:00

    When you open the editing form, it should be in dialog mode (WindowMode argument on the OpenForm line).  That's a safety issue to prevent users from trying to open more than one record for editing at the same time.

    Using dialog mode also pauses your code at the OpenForm line until the editing form is closed, at which point your code resumes running.  So, adding the line:

       Me.Requery

    right after the OpenForm line will refresh the data in your search form.

    20+ people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2012-11-28T22:02:23+00:00

    Thanks for reply both Gina and Marshall,

    My Search Form ("PCB Search") is actually left open while a 2nd form "PCB Add New" opens to add a new record.

    Meaning I will loose focus on the "PCB Search" form while updating the "PCB Add New".

    After the new record is saved in the "PCB Add New" form, I return to the "PCB Search" form.

    At this point I add a line suggested by Marshall to use Me.Requery to the On Got Focus property for forms this line:

    Private Sub Form_GotFocus()

    Me.Requery

    End Sub

    I suppose at this time the "PCB Search" form would have refreshed with the new record?

    Now I have a combo box in the "PCB Search" form.

    I check in that list, but the new record does not appear!

    Only when I click on Refresh All in the ribbon menu does it do what I want.

    4 people found this answer helpful.
    0 comments No comments
  3. Anonymous
    2012-11-28T22:34:24+00:00

    If you want just the combo box's list, instead of the form's data, to be "refreshed" then requery the combo box:

       Me.thecombobox.Requery

    Also note that the form's GotFocus event doesn't do much if there are any contros that can receive the focus.  You might(?) be able to use the form's Activate event instead, but I really don't like this idea.

    Just because the active form becomes your add new form does not prevent a user from clicking on your search form and starting another search and trying to add another record before finishing the priginal new record.  Things can get a little insane if that should happen and that's why I strongly suggest opening the add new form in dialog mode.  As I said before open the add new form in dialog mode also pauses your code so the next line with the Reqiery will wait until the add new form is closed.  No need to use any event to requery the combo box.

    2 people found this answer helpful.
    0 comments No comments
  4. Anonymous
    2012-11-28T06:19:46+00:00

    You would need to your Refresh or rather Requery code in the On-Close event of the pop up form.  Without more information hard to say whether that is what you are looking for.  Would help to know what it about the other Refresh functions you don't like.

    2 people found this answer helpful.
    0 comments No comments
  5. Anonymous
    2012-11-28T23:49:50+00:00

    Why is this?

    Don't know as we can't see your database.  But do you have any code in the After Update event of the combo box, like requerying the form maybe?

    1 person found this answer helpful.
    0 comments No comments