表单/子表单链接的不一致行为 [英] inconsistent behavior of form / subform link

查看:112
本文介绍了表单/子表单链接的不一致行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我希望你能帮助我解决我正在处理的两个数据库中的各种表单上多次出现的问题。当我第一次将子表单添加到链接子字段和主字段(主键和外键)的表单时,子表单将在主窗体上的主字段更改时自动更新(它在组合框中)。但是,当我在表单上工作更多时 - 使其更复杂,添加代码,搜索框等。子表单停止更新,但是即使更改主字段(当选择新值时)也停留在一条记录上从具有主字段作为其绑定列的组合框)。


我尝试在组合框的AfterUpdate事件中使用Me.Requery,但这会重新查询整个表单的内容,将其重置为第一条记录。我也试过我。[SUBFORMNAME] .Requery,但这似乎不起作用。


有谁知道为什么这个功能?子字段和主字段之间的自动链接并不总是有效?或者为什么重新查找子表单本身不起作用?我很感激任何建议。


非常感谢,提前。

Bridget

Hello all,
I am hoping that you can help me with a problem that has occurred numerous times on various forms in the two databases that I am working on. When I first add a subform to a form linking child and master fields (primary key and foreign key), the subform will automatically update when the master field on the main form is changed (it is in a combo box). However, when I work more on the form - making it a bit more complicated, adding code, search boxes, etc. The subform stops updating, but rather stays on one record even when the master field is changed (when a new value is selected from the combo box that has the master field as its bound column).

I have tried using Me.Requery in the AfterUpdate Event of the combo box, but this requeries the entire form''s contents, resetting it to the first record. I have also tried Me.[SUBFORMNAME].Requery, but this does not seem to work.

Does anyone know why this feature ? the automatic link between child and master fields does not always work? Or why requerying the subform itself does not work? I would appreciate any suggestions.

Many thanks, in advance.
Bridget

推荐答案

我在这方面不是很有经验我很害怕布里奇特,但我认为你应该更仔细地看待你正在做什么,当你认为它不再有效时。我的猜测是你正在做的事情使它停止工作,而不是它是系统本身的一个缺陷。下次发生时要特别注意并找出究竟发生了什么。这样,有人可以为你解释原因。
I''m not very experienced in this area I''m afraid Bridget, but I think you should probably be looking more closely at axactly what you are doing when you think it''s no longer working. My guess is that what you are doing makes it stop working, rather than it being a flaw in the system itself. Pay particular attention when it next happens and find out what exactly is occurring. That way someone may be able to explain why for you.


嗨布里奇特。我完全赞同NeoPa - 这是你正在采取的行动所引入的。在广泛使用子表单时,我从来没有遇到与主题细节记录的错误同步有关的问题。


当你谈到选择一个新的主要内容时,你能说清楚你的意思吗?主域的关键值?最根本的是必须更改单面记录的主键,特别是当已存在多方记录时。在这种情况下更改二级密钥不是子表单的工作。即使有关于1-many关系的Cascade更新,这样的更改也不会自动正确反映到多方记录中,因为Cascade Updates会处理对现有键值的修改,而不是批量替换这些值。


主表单子表单组合的父子关系会自动创建相关的辅助键。但是,如果您将主键更改为其他主键,则子表单本身不能将辅助键值更改为其他值 - 并且期望它们是不合理的。


无论如何,如果您有相关关系的关系完整性检查集(并且您应该),Access将根本不允许您替换主键,如果这样做会留下''孤儿''多边记录不再匹配一个一边记录。


-Stewart
Hi Bridget. I agree entirely with NeoPa - this is something that has been introduced by the actions you are taking. In extensive use of subforms I have never had issues relating to incorrect synchronisation of master-detail records the way you describe.

Could you clarify what you mean when you talk about selecting a new primary key value for the master field? It is most unusual to have to change the primary key for the one-side record at all, particularly when there are already many-side records in existence. It is not the job of a subform to change secondary keys in such circumstances. Even with Cascade Updates on for your 1-many relationship concerned such a change will not be reflected correctly into many-side records automatically, as Cascade Updates handles modifications to existing key values, not wholesale replacement of those values.

The parent-child relationship of a main-form sub-form combination takes care of the creation of related secondary keys automatically. However, if you change the primary key to a different one subforms cannot of themselves change the secondary key values to something else - and it is not reasonable to expect them to.

In any event, if you have relational integrity checking set for the relationship concerned (and you should) Access will simply not allow you to replace a primary key if to do so would leave ''orphaned'' many-side records that no longer match to a one-side record.

-Stewart


感谢NeoPa和Stewart的回复。我认为这可能揭示了我对形式如何/应该连接的理解中的一个缺陷。让我举一个具体的例子,看看是否有助于更多地了解它。


我有两种形式?frmAddSites?和?sfrmAddr1?以表格/子表格关系链接:


?frmAddSites?有一个控制源,tblSites。
Thank you NeoPa and Stewart for your responses. I think this may reveal a flaw in my understanding of how forms can /should connect. Let me give a specific example and see if that helps to shed some more light on it.

I have two forms ?frmAddSites? and ?sfrmAddr1? that are linked in a form/subform relationship:

?frmAddSites? has a control source, tblSites.
表,tblSites,包括:

SiteID?主键,autonumber

SiteName?文字

Addr1LKUP? number,一个名为?tluAddr1的地址表的外键?

(和其他一些描述性字段)


表tluAddr1包括以下字段:

Addr1ID?主键,自动编号

Addr1?文字

ZipCodeLKUP?数字,一个zipcode表的外键tluZipCode。


表tluZipCode保存每个邮政编码的城市和州信息:

邮政编码?主键

PostalCityLKUP?号码,tluPostalCity的外键

StateLKUP? number,tluState的外键
The table, tblSites, includes:
SiteID ? primary key, autonumber
SiteName ? text
Addr1LKUP ? number, foreign key to an address table called ?tluAddr1?.
(and a few other descriptive fields)

The table, tluAddr1, includes the fields:
Addr1ID ? primary key, autonumber
Addr1 ? text
ZipCodeLKUP ? number, foreign key to a zipcode table tluZipCode.

The table, tluZipCode, holds the city and state information for each zip code:
Zipcode ? primary key
PostalCityLKUP ? number, foreign key to tluPostalCity
StateLKUP ? number, foreign key to tluState

?sfrmAddr1?有一个控制源,qryAddr1。

?sfrmAddr1? has a control source, qryAddr1.

查询qryAddr1保存来自tluAddr1和相关查找表的所有地址信息(见上文):

Addr1ID

Addr1

PostalCity



ZipCode
The query, qryAddr1, holds all of the address information from tluAddr1 and associated lookup tables (see above):
Addr1ID
Addr1
PostalCity
State
ZipCode

?frmAddSites?具有以下控件:

txtSiteID - SiteID的文本框

txtSiteNm - SiteName的文本框

cboAddr1 - Addr1LKUP的组合框。

cboAddr1的行源是qryAddr1(绑定列是Addr1ID,可见列是Addr1)


?sfrmAddr1?具有以下控件:

txtAddr1ID - Addr1ID的文本框

txtCity - PostalCity的文本框

txtState - 状态的文本框

txtZipCode - ZipCode的文本框


这两个表格由
联系
Master Field Addr1LKUP

Child Field Addr1ID


我希望的功能是能够从主窗体(frmAddSites)上的cboAddr1中选择一个地址,并让子窗体(sfrmAddr1)自动显示相关的City, State和ZipCode。


cboAddr1的AfterUpdate事件中的代码Me.Requery重新查询整个表单,但也跳转到第一条记录。

代码Me.sfrmAddr1.Requery似乎没有做任何事情。

如果我更改记录中cboAddr1中的选择,然后移动到另一条记录,然后返回到我更改组合框选择的记录,显示子窗体上的正确记录。


这会产生更多ense?

这本身就是链接表单和子表单的有问题的方法吗?

当链接字段在主窗体中发生变化时,有没有办法让子窗体显示正确的记录?


再次感谢,

Bridget

?frmAddSites? has the following controls:
txtSiteID - text box for SiteID
txtSiteNm - text box for SiteName
cboAddr1 - combo box for Addr1LKUP.
The row source for the cboAddr1 is qryAddr1 (bound column is Addr1ID, visible column is Addr1)

?sfrmAddr1? has the following controls:
txtAddr1ID - text box for Addr1ID
txtCity - text box for PostalCity
txtState - text box for State
txtZipCode - text box for ZipCode

The two forms are linked by
Master Field Addr1LKUP
Child Field Addr1ID

The functionality I am hoping for is to be able to choose an address from the cboAddr1 on the main form (frmAddSites) and have the subform (sfrmAddr1) automatically display the associated City, State and ZipCode.

The code Me.Requery in the AfterUpdate Event of cboAddr1 requeries the entire form, but also jumps to the first record.
The code Me.sfrmAddr1.Requery does not seem to do anything.
If I change the selection in cboAddr1 on a record, then move to another record, and go back to the record where I changed the combo box selection, the correct record on the subform is displayed.

Does this make more sense?
Is this inherently a problematic way to link a form and subform?
Is there a way to make the subform display the correct record when the linked field changes in the main form?

Thanks again,
Bridget


这篇关于表单/子表单链接的不一致行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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