MS Access在子表单中保留ID字段,该表单中填充了父表单的ID [英] MS Access keep ID field in subform filled with ID from parent form

查看:98
本文介绍了MS Access在子表单中保留ID字段,该表单中填充了父表单的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我跳到可以输入新记录的位置时,父级的ID字段为空,因此连接断开.我正在寻找解决方法.

Everytime I jump to where I can enter e new record, the ID field from the parent is empty and so the connection is lost. I am looking for a workaround.

我有一个处理两个1:n关系的父表单

I have a parent form that deals with two 1:n relationships

(学校班级->学生,学校班级->考试).

(school-class --> pupils, school-class --> tests).

对于第一个关系,我使用了向导.一切正常.对于第二个,我在一个未绑定的列表中显示了已连接的测试.在列表下面是一个按钮,用于打开表单,以便为我来自的班级(父表单)输入新的记录(测试).因此,我通过VBA过滤了子表单,以便仅显示当前类的测试.这样也很好.

For the first relationship I used the wizard. Everything works find. For the second I show the connected tests in an unbound list. Under the list is a button opening the form for entering a new record (test) for the class I came from (parent form). So I filter the sub-form via VBA so that only the tests of the current class are shown. That works perfectly fine, too.

在通过已经与该类关联的测试进行移动时,正确的ID(已过滤的类)是相应输入字段的值.但是,当我进入新的新记录状态(所有字段均为空)时,与父级的连接中断,用户必须手动输入父级的ID(学校班级).

When moving through the tests already connected with the class the correct ID (of the class filtered) is the value of the corresponding input field. But when I come to the new new record state (all fields empty), then the connection to the parent breaks and the user has to manually enter the ID of the parent (school-class).

我的设置正确吗? 有没有更好的方法来创建一个子窗体,该子窗体提供(仅)输入与父数据连接的新记录? (也许子窗体中没有ID输入字段,是否通过VBA强制值传递?)

Is my setup correct? Is there a better way to create a subform that offers to (only) enter a new record connected to the parent data? (Maybe without the ID input field in the subform and passing of forcing the value via VBA?)

谢谢您的时间!

推荐答案

您可以使用默认值"设置测试"表单的classid,但请确保父表单在后台或在弹出窗口后打开.

You can use Default Value to set the classid of Tests form but be sure the parent form is open in background or behind the pop up.

在测试"表单的classid控件的属性表/数据"标签下,在默认值"单元格中输入:

Under Property Sheet/Data tab of Tests form's classid control, enter in Default Value cell:

=Forms!parentformname!classid

或者,在测试"表单的OnOpen事件中的 VBA 中:

Alternatively, in VBA in the Tests form's OnOpen Event:

Me.classid.DefaultValue = Forms!parentformname!classid

然后,您可以选择隐藏(可见-否)此classid控件,以便用户不要对其进行修改.始终建议永远不要让用户控制主键和外键.

You can then choose to hide (Visible - No) this classid control so users do not modify it. It's always advised to never allow users control of primary and foreign keys.

这篇关于MS Access在子表单中保留ID字段,该表单中填充了父表单的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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