[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to reference and reload a form from a dialog box

Posted on 2012-08-12
5
Medium Priority
?
604 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:Rich
  • 3
  • 2
5 Comments
 
LVL 58

Expert Comment

by:harfang
ID: 38286007
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°)
0
 
LVL 58

Expert Comment

by:harfang
ID: 38286013
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°)
0
 

Author Comment

by:Rich
ID: 38287417
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.
0
 
LVL 58

Accepted Solution

by:
harfang earned 2000 total points
ID: 38287521
Depending on the code in your Load event handler, you can call it like any other Sub in the module.

    DoCmd.OpenForm "frmDailySchedule", acDialog
    Form_Load

Open in new window

When I see I want to write something like this I often create a separate sub handling the common set-up code. I find it more readable and easier to maintain: when I make changes later I might not expect that an event handler is called from somewhere else...

Private Sub SetupDates()
    ' used to populate the unbound fields.
    ' ...
    ' (original Form Load code here)
    ' ...
End Sub

Private Sub cmdSchedule_Click()
    ' sample:
    DoCmd.OpenForm "frmDailySchedule", acDialog
    SetupDates   ' instead of Form_Load
End Sub

Private Sub Form_Load()
    ' code to handle the actual event, e.g. run-once initialization
    ' ...
    ' Populate initial dates in unbound controls:
    SetupDates
End Sub

Open in new window

Does that make sense?
(°v°)

PS: I should be leaving tomorrow for a couple of weeks, so if this isn't resolved until tonight, it would be better to ask a new question for that.
0
 

Author Closing Comment

by:Rich
ID: 38288185
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!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question