VBA access: Refreshing a form from another form

2019-01-27 06:23发布

问题:

EDIT: nevermind someone helped me. form_(name).recalc or form_(name).refresh: form_main.recalc

I have two forms: "main", "details". In the "main" form, I have a button that opens "details" in a dialog. The problem is that I have a checkbox in "details" and when in changes, I need to refresh "main". What command do that? Thank you

回答1:

I'm going to provide a different answer than the one you discovered for yourself:

Open the detail form with the acDialog switch, and then requery when it is closed. The event that opens the detail form would look like this (it would be in the main form):

  DoCmd.OpenForm "DetailForm", , , "ID=" & Me!ID, , acDialog 
  Me.Requery

What this does is pause the code with the detail form open. When you close the detail form, it will requery the main form.

This is the standard way of doing this kind of thing, seems to me.



回答2:

To anyone who may come behind me, the method above did not work if you are opening a pop-up from a subform attached to a main form.

What does work is change the "Got Focus" property on your main form by adding Me.Requery.

What that does is automatically requery and update the records in the form as soon as the pop-up is closed... and focus is automatically shifted to the main form.