Link to home
Start Free TrialLog in
Avatar of Rich
RichFlag for United States of America

asked on

How to reference and reload a form from a dialog box

I have an Access 2010 Navigation style form called frmNavigation.
In one of the tabs, I display a calendar form frmCalendar. On this calendar, I have various cells that have events that call DoCmd.OpenForm "frmDailySchedule", acDialog,...
When I close the frmDailySchedule dialog, I want to reload the calendar form using something like:
Forms![frmCalendar].Requery
Forms![frmCalendar].Refresh

Open in new window

in the onClose event (of a button to close the dialog.)

2 problems:

First, I get a runtime error saying it cannot find the referenced frmCalendar, so I am probably referring to it incorrectly since it is called from within the frmNaviagion, but when trying Forms![frmNavigation]![frmCalendar].Form.Requery I get the same error.

Second, when I start by opening the calendar directly (not through the frmNavigation but open frmCalendar), I do not get the runtime error, but the frmCalendar.requery or .refresh does not update the form contents.
Any ideas?
Thanks,
Rich
Avatar of Markus Fischer
Markus Fischer
Flag of Switzerland image

Let the form requery itself, like this:
    DoCmd.OpenForm "frmDailySchedule", acDialog
    Me.Requery

Open in new window

The acDialog mode has a side effect: it stops the calling VB code until the form is either closed or hidden.

(°v°)
For the sake of completeness, you need to use the name of the subform control, which isn't necessarily the name of the subform displayed in the control, e.g.:

Forms!frmNavigation!Child1.Form.Requery
Cheers!
(°v°)
Avatar of Rich

ASKER

Actually, I may have not explained correctly that the frmCalendar is primarily made up of unbound objects and that the data vales of these unbound objects are obtained and set during the form_load event of the frmCalendar, so really I do not want to requery but to rerun the form_load event. However, calling the Form_Load in place of where you had me put the Me.requery does call the form_load event, but then I get an error since the form already has the focus. I probably should open a new question on this, since your first response did in fact get me going (in what I hope) is the right direction.
ASKER CERTIFIED SOLUTION
Avatar of Markus Fischer
Markus Fischer
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rich

ASKER

Thank you very much. That helps  greatly, though it brings up a couple of other issues which I will post in a separate question. Have a good couple of weeks away!