如何使新记录跨MS Access中的一对一关系层叠? [英] How can I make new records cascade across a one to one relationship in MS Access?

查看:66
本文介绍了如何使新记录跨MS Access中的一对一关系层叠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在MS Access中的两个表之间具有一对一的关系,就像这样:

I currently have a one to one relationship between two tables in MS Access like so:

学生成绩

  • StudentResultsID(主键,自动编号)
  • 与课程有关的各个领域.

AVETMISS数据

  • StudentResultsID(主键,长整数)
  • 与每个特定的纸质表格相关的各个字段,每次注册必须由学生填写.

当用户向学生结果中添加新记录时(每次学生注册课程时都会发生),我想在AVETMISS数据中创建匹配记录.我以为这是创建关系和强制执行参照完整性的功能,但是即使启用了此选项,我仍然会出现不一致的情况.

When the user adds a new record to Student Results (this occurs everytime a student is enrolled into a course) I want to create a matching record in AVETMISS Data. I thought this was a function of creating the relationship and enforcing referential integrity, however even with this option turned on I keep getting inconsistencies.

如果有办法在表(或查询)的设置以及关系中做到这一点,那将是我的首选解决方案.

If there is a way to make this happen in the setup of the tables (or queries) and the relationship that would be my preferred solution.

如果这不可能,我认为可行但不理想的一种解决方案是为AVETMISS Data设置表单,使其在打开时运行某些代码或宏.

If this is not possible, one solution that I think would work, but is much less ideal, is to rig the form for AVETMISS Data to run some code or macro when it is opened.

Something like this in the On Load property:

Does this StudentResultsID exist in AVETMISS Data?

Yes - Do nothing

No - Create new record with this StudentResultsID

在我看来,学生成绩"表单中的插入后"属性可能是这种解决方案的更好选择.

It's occured to me that the 'After Insert' property in the Student Results form may be a better candidate for this kind of solution.

如果我必须诉诸此解决方案,我将非常感谢其中的一些指导,因为我几乎不了解Visual Basic,也不想为三行代码片段学习它.

If I must resort to this solution I would really appreciate some guidance in this as I know next to nothing about Visual Basic and don't want to learn it for a 3-line snippet of code.

请注意-在研究期间,我发现很多人质疑使用一对一关系的背后原因.我已经读过反对使用这些关系的论点,并且可以肯定,这对于我的情况是完全必要的.

Please note - During my research I found a lot of people questioning the reasoning behind using a one to one relationship. I have read the arguments against using these relationships and I am certain that it is completely necessary for my situation.

推荐答案

根据您的描述,我认为您可能无需代码即可解决此问题.

Based on your description, I think you may be able to solve this with no code.

根据学生结果创建一个表单,并根据AVETMISS数据创建另一个表单.然后将第二个窗体添加到第一个窗体的子窗体控件中.将链接主/子属性设置为StudentResultsID.

Create a form based on Student Results and a second form based on AVETMISS Data. Then add that second form to a subform control on the first form. Set the link master/child property to StudentResultsID.

在表单视图中时,子表单应显示AVETMISS数据行,该行的StudentResultsID与在父表单中显示的当前行匹配.

When in form view, the subform should display the AVETMISS Data row whose StudentResultsID matches the current row displayed in the parent form.

如果当前父表单StudentResultsID不存在子表单匹配项,则可以通过在其他任何可用的子表单绑定数据控件(StudentResultsID除外)中键入一个值来添加一个子表单.保存后,该新记录将具有与父表单当前行相同的StudentResultsID.

If no subform match exists for the current parent form StudentResultsID, you can add one by typing a value into any other the available subform bound data controls (other than StudentResultsID). When saved, that new record will have the same StudentResultsID as the parent form current row.

链接主/子属性可确保子链接字段(StudentResultsID)继承"主字段值.

The link master/child property ensures the child link field (StudentResultsID) "inherits" the master field value.

这篇关于如何使新记录跨MS Access中的一对一关系层叠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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