MS访问——在一个报告中使用多个查询

时间:2022-04-17 23:50:06

I have about 35 queries in a large MS Access (2007) database that I would like to use in a report. However, I don't want to create reports for each query, but would rather include multiple queries in one report. The other questions relating to this on SO seem to be related to tables, but I am mainly concerned with just queries.

我在一个大型MS Access(2007)数据库中有大约35个查询,我想在报告中使用。但是,我不希望为每个查询创建报告,而是希望在一个报告中包含多个查询。与此相关的其他问题似乎与表有关,但我主要关注的是查询。

I have looked at several solutions so far, none of which seem to help:

到目前为止,我已经研究了几种解决方案,但似乎没有一种能奏效:

1) DLookup - returns one value. I need to populate a report with many values from each query.

1) DLookup——返回一个值。我需要用每个查询的许多值填充报表。

2) Subreports - I have tried to create text boxes to link my query data, but since they are unbound, it won't let me.

2)子报告——我尝试创建文本框来链接查询数据,但是由于它们是未绑定的,所以它不允许我这样做。

3) Yelling at it. I keep yelling at Access and it doesn't seem to help.

3)大喊大叫。我不停地对着通道大喊大叫,但似乎没什么用。

4) One giant query to get the values from all the smaller queries - it doesn't recognize the expressions I built in the smaller queries. Example: CustomerCount = DCount("[Customer_ID]","[Customers]"). Error: 'CustomerCount' is unrecognized.

4)一个巨大的查询从所有较小的查询中获取值——它不承认我在较小的查询中构建的表达式。例如:CustomerCount = DCount(“[Customer_ID]”,“[客户]”)。错误:“CustomerCount”是无法识别的。

Any ideas would be greatly appreciated.

任何想法都将非常感谢。

Thanks,

谢谢,

2 个解决方案

#1


3  

If you are creating a report from one query that is made up of multiple subqueries, you can do this by populating textboxes. If looking at the properties on the report > Data tab > Control Source, you would place the name of the your subquery from your giant query and then the value you that you want.

如果您正在从一个由多个子查询组成的查询创建一个报告,您可以通过填充文本框来实现这一点。如果查看报告> Data选项卡>控制源上的属性,您将从大型查询中放置子查询的名称,然后放置您想要的值。

For example:

例如:

Master query

    SELECT 
        [Deb<30].CountOfACCT_ID, [Deb<30].SumOfB001, 
        [Deb<60].CountOfACCT_ID, [Deb<60].SumOfB001, 
        [Deb<90].CountOfACCT_ID, [Deb<90].SumOfB001, 
        [Deb>90].CountOfACCT_ID, [Deb>90].SumOfB001, 
        TodaysHD.CountOfACCT_ID, TodaysHD.SumOfB001, 
        TodaysLD.CountOfACCT_ID, TodaysLD.SumOfB001, 
        Part.CountOfACCT_ID, Part.SumOfB001, 
    FROM [Deb<30], [Deb<60], [Deb<90], [Deb>90], TodaysHD, TodaysLD, Part;

Each of the items in the FROM portion are subqueries being pulled into the master query. Then in your report you would populate the Control Source with [Deb<30].CountOfACCT_ID or whatever value you need from the master query. I have this setup in multiple reports in my application so it should work.

FROM部分中的每一项都是被拉进主查询的子查询。然后在报表中,您将使用[Deb<30]填充控制源。CountOfACCT_ID或从主查询中需要的任何值。我在应用程序的多个报告中都有这种设置,因此它应该可以工作。

#2


0  

as for 2) you should be able to bind your controls, your subreport should have a record-source.

至于2)你应该能够绑定你的控件,你的子报告应该有一个记录源。

Else, try listboxes, their graphical apperance isn't exactly flexible, but they might get the job done.

否则,试试listboxes,他们的图形化评估并不是很灵活,但是他们可能会完成工作。

regards, //t

问候,/ / t

#1


3  

If you are creating a report from one query that is made up of multiple subqueries, you can do this by populating textboxes. If looking at the properties on the report > Data tab > Control Source, you would place the name of the your subquery from your giant query and then the value you that you want.

如果您正在从一个由多个子查询组成的查询创建一个报告,您可以通过填充文本框来实现这一点。如果查看报告> Data选项卡>控制源上的属性,您将从大型查询中放置子查询的名称,然后放置您想要的值。

For example:

例如:

Master query

    SELECT 
        [Deb<30].CountOfACCT_ID, [Deb<30].SumOfB001, 
        [Deb<60].CountOfACCT_ID, [Deb<60].SumOfB001, 
        [Deb<90].CountOfACCT_ID, [Deb<90].SumOfB001, 
        [Deb>90].CountOfACCT_ID, [Deb>90].SumOfB001, 
        TodaysHD.CountOfACCT_ID, TodaysHD.SumOfB001, 
        TodaysLD.CountOfACCT_ID, TodaysLD.SumOfB001, 
        Part.CountOfACCT_ID, Part.SumOfB001, 
    FROM [Deb<30], [Deb<60], [Deb<90], [Deb>90], TodaysHD, TodaysLD, Part;

Each of the items in the FROM portion are subqueries being pulled into the master query. Then in your report you would populate the Control Source with [Deb<30].CountOfACCT_ID or whatever value you need from the master query. I have this setup in multiple reports in my application so it should work.

FROM部分中的每一项都是被拉进主查询的子查询。然后在报表中,您将使用[Deb<30]填充控制源。CountOfACCT_ID或从主查询中需要的任何值。我在应用程序的多个报告中都有这种设置,因此它应该可以工作。

#2


0  

as for 2) you should be able to bind your controls, your subreport should have a record-source.

至于2)你应该能够绑定你的控件,你的子报告应该有一个记录源。

Else, try listboxes, their graphical apperance isn't exactly flexible, but they might get the job done.

否则,试试listboxes,他们的图形化评估并不是很灵活,但是他们可能会完成工作。

regards, //t

问候,/ / t