简体   繁体   中英

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. 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. B is linked to D, so it shows all corresponding records for the currently selected chemical. Here a quick overview of the database:

DB Relationships

The query for A [stoffe_abfrage subform]:

 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]:

 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:

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

(B is linked from [stoff_id] on B, to 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. Unfortunately, referencing the primary key (stoff_id) on A from B only works if B is not empty. 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.


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. When B currently has no records, I get a runtime error because of an empty value.
  • 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. 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.

for the second test I tried 2 different approaches:

  1. Get D from C via parent

     =[Me].[Parent].[MainLinkStoff]
  2. Get the D value manually from forms

    =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. If the chemical has no current records in B, D on the parent form displays correctly but the dummy is suddenly empty too. 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. (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. Object references created by wizards and internal tools in those versions use different formulations ([Forms]=[Formulare] etc.). 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. This worked most of the time, but quite often, especially in fringe cases, it resulted in Access messing up the references completely. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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