vba 如何刷新访问表单

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/212234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 09:25:10  来源:igfitidea点击:

How to refresh an access form

vbams-accessaccess-vbarefresh

提问by Varun Mahajan

I am building an MS Access application in which all the forms are modal. However, after data change in a form, I want to refresh the parent form of this form with newer data. Is there any way to do it. To elaborate further :

我正在构建一个 MS Access 应用程序,其中所有表单都是模态的。但是,在表单中的数据更改后,我想用更新的数据刷新此表单的父表单。有什么办法可以做到。进一步阐述:

Consider there are two forms, Form A and Form B. Both are modal form. From Form A, I initiate Form B, and now Form B has the user attention. But at the close of form B, I want to refresh the Form A. Is there a way to do it?

考虑有两种形式,形式 A 和形式 B。两者都是模态形式。我从 Form A 启动了 Form B,现在 Form B 引起了用户的注意。但是在表格 B 结束时,我想刷新表格 A。有没有办法做到这一点?

回答by Fionnuala

You can repaint and / or requery:

您可以重新绘制和/或重新查询:

On the close event of form B:

在表格 B 的关闭事件上:

Forms!FormA.Requery

Is this what you mean?

你是这个意思吗?

回答by Fionnuala

No, it is like I want to run Form_Load of Form A,if it is possible

不,就像我想运行 Form A 的 Form_Load,如果可能的话

-- Varun Mahajan

——瓦伦·马哈詹

The usual way to do this is to put the relevant code in a procedure that can be called by both forms. It is best put the code in a standard module, but you could have it on Form a:

通常的做法是将相关代码放在两个表单都可以调用的过程中。最好将代码放在标准模块中,但您可以将其放在 Form a 中:

Form B:

表格B:

Sub RunFormALoad()
   Forms!FormA.ToDoOnLoad
End Sub

Form A:

表格A:

Public Sub Form_Load()
    ToDoOnLoad
End Sub    

Sub ToDoOnLoad()
    txtText = "Hi"
End Sub

回答by BIBD

"Requery" is indeed what you what you want to run, but you could do that in Form A's "On Got Focus" event. If you have code in your Form_Load, perhaps you can move it to Form_Got_Focus.

“重新查询”确实是您想要运行的内容,但您可以在 Form A 的“On Got Focus”事件中执行此操作。如果您的 Form_Load 中有代码,也许您可​​以将其移至 Form_Got_Focus。

回答by tony gil

I recommend that you use REQUERYthe specific combo box whose data you have changed AND that you do it after the Cmd.Closestatement. that way, if you were inputing data, that data is also requeried.

我建议您使用REQUERY已更改数据的特定组合框,并在Cmd.Close语句之后进行。这样,如果您正在输入数据,也会重新查询该数据。

DoCmd.Close
Forms![Form_Name]![Combo_Box_Name].Requery

you might also want to point to the recently changed value

您可能还想指向最近更改的值

Dim id As Integer
id = Me.[Index_Field]
DoCmd.Close
Forms![Form_Name]![Combo_Box_Name].Requery
Forms![Form_Name]![Combo_Box_Name] = id

this example supposes that you opened a form to input data into a secondary table.

此示例假设您打开了一个表单以将数据输入到辅助表中。

let us say you save School_Index and School_Name in a School table and refer to it in a Student table (which contains only the School_Index field). while you are editing a student, you need to associate him with a school that is not in your School table, etc etc

假设您将 School_Index 和 School_Name 保存在 School 表中,并在 Student 表(仅包含 School_Index 字段)中引用它。在编辑学生时,您需要将他与不在您的 School 表中的学校相关联,等等

回答by dinesh

to refresh the form you need to type -me.refresh in the button event on click

刷新您需要键入的表单 -单击时按钮事件中的 me.refresh