从子窗体更新主窗体 [英] Update Main Form from Subform

查看:82
本文介绍了从子窗体更新主窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此很新,所以我会尽量保持清醒。我有一个存储员工信息和所有职位的数据库。我有一个基于查询的主窗体,并在Job表中显示所有作业代码和作业。我还在主窗体中有一个文本框,用于跟踪此职位的可用职位总数:

= DSum(" [NumberofPositions]",[JobVacancy]" ;,[code] = [JobVacancy]![JobCode]")

其中JobVacancy是一个包含JobCode的表,Department,Division,NumberofPositions和Code是存储在Job中的作业代码表格。


我的子表单基于另一个查询,该查询从JobVacancy表中提取与每个作业代码相关的部门和部门。它还有来自JobVacancy表的NumberofPositions。我的子表单和主表单由作业代码链接,子表单是一个连续的表单。


基本上用户打开主表单时会看到的是作业代码和标题主要形式,以及总职位的框。 (还有更多的信息显示,但我相信这与问题无关)。然后,他们必须通过组合框选择子表单中的部门和部门,并输入可用的职位数。每个工作代码可能与许多部门和部门相关联。一切都很好,除了我希望主窗体中的文本框在子窗体中更改后立即更新位置总数。目前,只有关闭然后重新打开表单才会更新。任何建议,将不胜感激!!请记住,我从未在visual basic中编码,如果是解决方案,则需要非常具体的说明。


谢谢!

Michelle

解决方案

在子窗体中,当用户更改要在主窗体中反映的值时,您需要在控件的AfterUpdate事件后面编写一个简单的重新查询代码正在输入信息。一步一步,它看起来像这样:


1.在子窗体的窗体设计视图中,调出用户输入新数据的文本框/组合框等的属性窗口in。

2.转到事件选项卡。

3.单击After Update行右侧的边距。

4.点击...字符

5.选择代码生成器。

6.在出现的窗口中输入以下代码:

展开 | 选择 | Wrap | 行号

顺便说一下,您可以将此重新查询代码放在任意数量的控件中,或者只放在最后一个将要更新的控件中。


请记住,如果您的查询很复杂,那么重新查询可能会显着降低数据库响应速度。


希望这会有所帮助。


问候,

Scott


感谢您的回复!这很有效,除非我做出改变,它会跳回到第一条记录......我有257条记录,所以这有点烦人。无论如何在更新后将其保留在当前记录中吗?


I''m fairly new to this so I''ll try to be as clear as possible. I have a database that stores employee information and all job titles available. I have a main form that is based from a query and displays all job codes and job titles in the Job table. I also have a text box in the main form to keep track of the total number of positions available for this job title:
=DSum("[NumberofPositions]","[JobVacancy]","[code]=[JobVacancy]![JobCode]")
Where JobVacancy is a table that contains JobCode, Department, Division, NumberofPositions and Code is the job code stored in the Job table.

My subform is based on another query that pulls the department and division related to each job code from the JobVacancy table. It also has the NumberofPositions from the JobVacancy table on it. My subform and main form are linked by the job codes and the subform is a continuous form.

Basically what the user will see when they open the main form is the job code and title in the main form, and a box for the Total Positions. (There is a bit more info shown as well, but I believe it''s irrelevant for the problem). Then they will have to select a department and division in the subform through combo boxes and input how many positions are available. Each job code may be associated with many department and divisions. Everything works great, except I want the textbox in the main form to update the total number of positions as soon as it is changed in the subform. Currently, it only updates if I close and then reopen the form. Any suggestions would be appreciated!! Please keep in mind that I have never coded in visual basic and would need very specific instructions if that is the solution.

Thanks!
Michelle

解决方案

In your subform, when a user changes a value that you want reflected in the main form, you will need to write a simple requery code behind the AfterUpdate event of the control they are entering the information into. Step by step, it looks like this:

1. In form design view of subform, bring up the properties window of the text box/combo box etc that the user enters the new data in.
2. Go to the Events tab.
3. Click in the margin to the right of the After Update line.
4. click the "..." character
5. Choose Code builder.
6. In the window that comes up write this code:

Expand|Select|Wrap|Line Numbers


BTW, you can put this requery code in as many of the controls as you want, or just in the last one that will be updated.

Keep in mind that if your query is complex, the requery''ing may slow your db response down noticeably.

Hope this helps.

Regards,
Scott


Thanks for the response! That works great, except as soon as I make a change, it skips back to the first record...I have 257 records so that''s kind of annoying. Is there anyway to keep it on the current record after it updates?


这篇关于从子窗体更新主窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆