简体   繁体   English

显示来自组 header 中的子查询的附件时出错

[英]Error showing an attachment from sub-query in group header

I have a table people and a table areas.我有一个桌子人和一个桌子区域。 Every person belongs to an area, and every area has a map stored as an attachment field.每个人都属于一个区域,每个区域都有一个 map 存储为附件字段。 I am trying to create a report to show the people grouped by area with a map after every group.我正在尝试创建一个报告,以在每个组之后显示按区域分组的人员 map。 I also need for every person some data from another table, and I tried using a subquery for that.我还需要为每个人提供另一个表中的一些数据,我尝试为此使用子查询。 The problem is that you cannot use a report group with a subquery.问题是您不能将报表组与子查询一起使用。 I solved that problem by saving the query separately and using我通过单独保存查询并使用解决了这个问题

SELECT * FROM query1;

(where query1 is my query with a join and subqueries) in my report source. (其中query1是我的带有连接和子查询的查询)在我的报告源中。 Then I added a group by area.id to the report with a footer.然后我在带有页脚的报告中添加了一个按area.id的组。 In that footer I can show the area name etc. No problem, but if I try to display the map I get a blank map.在该页脚中,我可以显示区域名称等。没问题,但如果我尝试显示 map,我会得到一个空白 map。 I also tried changing my query to我也尝试将我的查询更改为

SELECT person.name, ..., area.name, area.map, ... FROM query1;

It still works without the map, but if I add the attachment control I get an error saying "you tried to execute a query that does not include the specified expression name".如果没有 map,它仍然可以工作,但是如果我添加附件控件,我会收到一条错误消息,提示“您尝试执行不包含指定表达式名称的查询”。

query1 looks something like this: query1看起来像这样:

SELECT person.*, area.*, 
    (SELECT a FROM b WHERE b.id = person.id AND b.year = Year(Now())),
    (SELECT a FROM b WHERE b.id = person.id AND b.year = Year(Now()) - 1),
    (SELECT a FROM b WHERE b.id = person.id AND b.year = Year(Now()) - 2)
FROM person INNER JOIN area ON person.areaID = area.ID

Is there a way to do this in Access?有没有办法在 Access 中做到这一点?

Options:选项:

  1. use Dlookup() to pull value from table b.使用 Dlookup() 从表 b 中提取值。 Expression can be in query or textbox.表达式可以在查询或文本框中。 DLookUp("a","b","ID=" & [Person.ID] & " AND Year=Year(Date())")

  2. build a CROSSTAB query with table b.使用表 b 构建一个 CROSSTAB 查询。 Join that query to Person table in Query1.将该查询加入到 Query1 中的 Person 表。 Problem with this approach is dynamic nature of column headers in CROSSTAB.这种方法的问题是 CROSSTAB 中列标题的动态特性。 There are ways to deal with and it is a common topic.有办法处理,这是一个共同的话题。

In both options, reference Query1 directly as report RecordSource or put its SQL statement in report RecordSource - don't use SELECT * FROM Query1;在这两个选项中,直接引用 Query1 作为报告 RecordSource 或将其 SQL 语句放在报告 RecordSource 中 - 不要使用SELECT * FROM Query1;

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

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