将值从主窗体传递给子窗体 [英] pass a value from a main form to a subform

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

问题描述

你好,


我是Access和VB的初学者。

在我的数据库中,我有一个包含子表单的表单。

子表单是来自不同于主表单表的表的查询。这些表还没有链接。


主表单用于在表格中创建新条目/新行。


我想要做的是使用主窗体中的primery键并将值复制到子窗体中的字段中。在子窗体中,我首先需要选择一些行。当我选择项目时,必须复制该值,在值旁边有一个字段。


我尝试不同的东西,但我找不到有效的解决方案。

其中一个解决方案,对我来说最合乎逻辑的是,当我在列表中选择我想要的元素时,添加一个'on click''。我使用了表达式构建器,但它不起作用。其中一个表达式是这样的:

Hi There,

I''m a beginer in Access and VB.
In my Database, I''ve got a form with a subform.
the subform is a query from a table different than the table of the main form. those tables don''t have a link yet.

the main form is being use to create a new entry/ a new row in the table.

What I want to do is use the primery key from the main form and copy the value in a field in the subform. In the subform, I first need to select some rows. The value has to be copied when I select the item, there is a field beside where the value should be.

I try different thing but I haven''t find a solution that work.
one of the solution, the most logical for me, is to add an event ''on click'' when I choose which element I want in the list. I used the expression builder but it doesn''t work. one of the expression was something like this:

展开 | 选择 | Wrap | 行号

推荐答案

嗨再次,


我只是尝试将此代码放入''点击''事件中

Hi again,

I just try to put this code in the ''on click'' event

展开 | 选择 | Wrap | 行号


你实际上必须把它带回到两个表之间的关系。


如果我们调用Table1表的名称在主窗体后面,Table2是子窗体后面的表的名称。现在Table1有一个名为Table1_ID的ID字段,Table2有一个名为Table2_ID的ID字段和一个名为Table1_ID的外键。


现在,Table2_ID的数据类型是自动编号是很重要的。还有其他方法,但这是最简单的方法。将Table2中Table1_ID字段的默认值设置为...
You actually have to take this back to the relationship between the two tables.

If we call Table1 the name of the table behind the main form and Table2 the name of the table behind the subform. Now Table1 has an ID field called Table1_ID and Table2 has an ID field called Table2_ID and a foreign key called Table1_ID.

Now it''s important that Table2_ID has a data type of autonumber. There are other ways of doing it but this is the simplest. Set the default value of of the Table1_ID field in Table2 to ...
展开 | 选择 | Wrap | 行号


谢谢你,


事情是,在Table2中,已经存在一些现有领域,我不想创建新领域,至少在这种情况下不是。


实际上,在Table1中,通过归档主窗体创建了一个新行。

我实际上想通过在子表单中选择要复制的字段来将新创建的Table1 primery键的值复制到Table2中的某个字段。


你是解决方案是一种工作,因为在子表单中,如果我想创建一个新行,那么Primery键将被复制,但它不会复制到我正在选择的字段中......


希望很清楚。

Philippe
Thanks for this,

the thing is that in Table2, there are already some existing field, I don''t want o create new ones, at least not in this case.

In fact it is in Table1 that a new row is created by filing up the main form.
I actually want to copy the value of the Table1 primery key newly created to some field in Table2, by selecting in the subform which field to copy.

You''re solution is sort of work since in the subform, if i wanted to create a new row, then the Primery key would be copied, but it does''t copy in field that I''m selecteing afterthat...

Hope it is clear.
Philippe


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

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