VBA access: Refreshing a form from another form's code

与世无争的帅哥 提交于 2019-12-22 17:38:58

问题


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.



来源:https://stackoverflow.com/questions/6426144/vba-access-refreshing-a-form-from-another-forms-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!