简体   繁体   English

ms访问:空子表单查询导致空父控件引用

[英]ms access: Empty subform query causes empty parent control reference

The Problem问题

I have two continuous subforms A and B in a tabular layout on a main form C.我在主表单 C 的表格布局中有两个连续的子表单 A 和 B。 The first has the names of some chemicals, the second has corresponding info on those chemicals.第一个有一些化学品的名称,第二个有这些化学品的相应信息。 I have a field D on C that takes the value of the primary key [stoff_id] of A for the current record.我在 C 上有一个字段 D,它采用当前记录的 A 的主键 [stoff_id] 的值。 B is linked to D, so it shows all corresponding records for the currently selected chemical. B 链接到 D,因此它显示当前所选化学品的所有相应记录。 Here a quick overview of the database:这里是数据库的快速概览:

DB Relationships数据库关系

The query for A [stoffe_abfrage subform]: A [stoffe_abfrage 子形式] 的查询:

 SELECT chemikalien_tabelle.stoff_id, chemikalien_tabelle.bezeichnung, chemikalien_tabelle.einsatzgebiet, kategorie_tabelle.kategorie FROM kategorie_tabelle INNER JOIN chemikalien_tabelle ON kategorie_tabelle.[kategorie_id] = chemikalien_tabelle.[kategorie_id];

The query for B [tmb_abfrage subform]: B [tmb_abfrage 子形式] 的查询:

 SELECT tmb_tabelle.version, tmb_tabelle.datum_aktualisiert, tmb_tabelle.datum_upload, sprachen_tabelle.bezeichnung, tmb_link.stoff_id, tmb_link.tmb_id, tmb_tabelle.datei.FileType, tmb_tabelle.datei FROM (sprachen_tabelle INNER JOIN tmb_tabelle ON sprachen_tabelle. [sprache_id] = tmb_tabelle.[sprache_id]) INNER JOIN tmb_link ON tmb_tabelle.[tmb_id] = tmb_link.[tmb_id];

The value of the control D [MainLinkStoff] on C: C 上的控件 D [MainLinkStoff] 的值:

 =[stoffe_abfrage subform].[Formular] [stoff_id]

(B is linked from [stoff_id] on B, to D) (B 从 B 上的 [stoff_id] 链接到 D)

I want to use the primary key value on A in a button event on B, so I need a way to reference it.我想在 B 上的按钮事件中使用 A 上的主键值,所以我需要一种方法来引用它。 Unfortunately, referencing the primary key (stoff_id) on A from B only works if B is not empty.不幸的是,仅当 B 不为空时,从 B 引用 A 上的主键 (stoff_id) 才有效。 If there are no records on B, then the reference of stoff_id on A from B turns empty, event though the value of the control on A itself is nonempty.如果 B 上没有记录,则从 B 对 A 的 stoff_id 的引用变为空,尽管 A 上的控件的值本身是非空的。


What I have tried:我试过的:

  • I tried getting [stoff_id] from A and I have also tried getting the value from D, but both have resulted in the same issue.我尝试从 A 获取 [stoff_id] 并且我也尝试从 D 获取值,但两者都导致了相同的问题。 When B currently has no records, I get a runtime error because of an empty value.当 B 当前没有记录时,由于值为空,我收到运行时错误。
  • I was curious why this would be the case if getting the value directly from D for example, since that field has a value and is never empty.我很好奇为什么如果直接从 D 获取值会出现这种情况,因为该字段有一个值并且永远不会为空。 So I made a dummy textbox [dummyB] on B where my button is located in the header section and set the value to be equal to D.所以我在 B 上创建了一个虚拟文本框 [dummyB],我的按钮位于 header 部分,并将值设置为等于 D。

for the second test I tried 2 different approaches:对于第二个测试,我尝试了 2 种不同的方法:

  1. Get D from C via parent通过父级从 C 获取 D

     =[Me].[Parent].[MainLinkStoff]
  2. Get the D value manually from forms从 forms 手动获取 D 值

    =Formulare.[HUB] [NavigationSubform] Formular [MainLinkStoff]

In both approaches, if the chemical already has records in B, the dummy and D both display the value of the primary key correctly and are identical.在这两种方法中,如果化学物质在 B 中已经有记录,则 dummy 和 D 都正确显示主键的值并且是相同的。 If the chemical has no current records in B, D on the parent form displays correctly but the dummy is suddenly empty too.如果化学品在 B 中没有当前记录,则父表单上的 D 显示正确,但虚拟对象也突然为空。 Why is this?为什么是这样? Here some images of what I mean.这里有一些我的意思的图像。 D is in the top middle of the form C, the dummy adjacent to it on the right subform B. A is on the left, B on the right. D 在表格 C 的顶部中间,在右侧子表格 B 上与它相邻的假人。A 在左侧,B 在右侧。 (invisible borders) (隐形边框)

Existing records现有记录

No existing records没有现有记录


So, I found the issue.所以,我发现了这个问题。 I was working on the project from 2 different computers.我正在使用两台不同的计算机进行该项目。 One used the German language version of Access, the other the English language one.一个使用德语版本的 Access,另一个使用英语版本。 Object references created by wizards and internal tools in those versions use different formulations ([Forms]=[Formulare] etc.).在这些版本中由向导和内部工具创建的 Object 参考使用不同的公式([Forms]=[Formulare] 等)。 What ended up happening was that some object references in SQL queries, criteria etc. were in German, the objects themselves had further references that were in English, which in turn referenced others that were in German again.最终发生的事情是 SQL 查询、标准等中的一些 object 引用是德文的,对象本身有进一步的英文引用,而这些引用又引用了其他德文的引用。 This worked most of the time, but quite often, especially in fringe cases, it resulted in Access messing up the references completely.这在大多数情况下都有效,但通常情况下,尤其是在边缘情况下,它会导致 Access 完全弄乱了引用。 For example in cases where queries or field values were returned empty.例如,在查询或字段值返回空的情况下。 I am not entirely sure how Access manages the conversion of references in different language versions, but there seem to be issues with it when mixing them.我不完全确定 Access 如何管理不同语言版本的引用转换,但在混合它们时似乎存在问题。 The solution was to choose one language version to use for references, and stick with that formulation for the entire project.解决方案是选择一种语言版本作为参考,并在整个项目中坚持该表述。 I tested both, and either German or English work fine, on either version of accesss.我在任一版本的访问中都进行了测试,无论是德语还是英语都可以正常工作。 Mixing them up within the same project however, creates problems.然而,将它们混合在同一个项目中会产生问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM