I have 4 queries in my database and to refresh the contents of the forms each time I rerun the query (via a button), I have vba to just close and reopen the form. This worked before, but this method does not work now that I decided to embed my reports within my query forms (which are inside a navigation control element). I haven't been able to find a "refresh" method that will work with this setup. I tried the Requery method, but it does not update my form. Here is what I have:
Background info:
- Main form = MainMenu
- Navigation control element = NavigationSubform
- Form I put inside NavigationSubform = *equipment_at_location
- Subform within *equipment_at_location (which I want to "refresh") = rpt_equipment_at_location
Code which runs when I click my "run query" button:
Forms!MainMenu!NavigationSubform.Form!rpt_equipment_at_location.Requery
I've also tried this, but it does the same thing:
Me.rpt_equipment_at_location.Requery
rpt_equipment_at_location report after clicking my "run query" button
I know the path is correct because this code causes the form to "blink" (as if the form was refreshed), but the form is not updated with the current information of the query. If I open the rpt_equipment_at_location linked parent form, all the information is updated and changes accurately each time the query is run, but that form is not represented that way as a subform within my navigation control form. It just shows one record and when I Requery, that one form either doesn't change or goes blank. My Linking Fields are populated so shouldn't the rpt_equipment_at_location subform update when the form its linked to is updated?
Let me know if I need to clear anything up. I'd greatly appreciate any help!!
CodePudding user response:
I got it working! I'm not entirely sure what happened but I'll try to explain in case this happens to anyone else:
It is important to note that my report is based on a query, so when I placed it into my form (drag and drop), it should have prompted me for certain values I called for in that query's SQL code (which referenced other data elements in various forms), but it did not since I was in design view. When I switched to layout view and placed my subreport in, it prompted me for those values, which initialized what records are initially displayed in the form. After having all my records pre-initialized in the form, the Requery code worked.
Sorry if this doesn't make sense. I'm not sure why Access would be like this or why this didn't work through design view, but this is what worked for me.