设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 2206|回复: 2
打印 上一主题 下一主题

[模块/函数] Learn how to create a dynamic monthly crosstab reports

[复制链接]
跳转到指定楼层
1#
发表于 2008-6-15 00:19:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Dynamic Monthly
Crosstab Report Try not to use "absolute" column headings for dates. You could possibly use "relative" dates.
This tip shows how to create monthly headings but will work just as well with other date intervals such as weeks, days, years, or other. For instance to change to weeks, change the DateDiff() and DateAdd() functions to use "ww" rather than "m".

For instance:

Form: frmA
Text Box: txtEndDate
Table: tblSales
Field: SaleDate
You want to show 12 months of sales in columns of a crosstab report.
Set the query parameters by menuing: Query|Parameters and enter:
    Forms!frmA!txtEndDate     Date/Time

Use this expression for your Column Headings:
ColHead:"Mth" & DateDiff("m",[SaleDate],Forms!frmA!txtEndDate)
This will produce Mth0, Mth1, Mth2, Mth3,... where Mth0 is sales from the same month as the ending date on your form. Mth1 is the previous month etc.

Set your queries Column Headings property to:
Column Headings: "Mth0", "Mth1", "Mth2", "Mth3",.., "Mth11"
Build your report based on these "relative" months.

If you need column labels in your report, use text boxes with control sources of:
=DateAdd("m",0,Forms!frmA!txtEndDate)
=DateAdd("m",-1,Forms!frmA!txtEndDate)
=DateAdd("m",-2,Forms!frmA!txtEndDate)
=DateAdd("m",-3,Forms!frmA!txtEndDate)
...

< This solution requires no code and will run fairly quickly.
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2008-6-15 04:40:51 | 只看该作者
谢谢分享,不过我想知道把Crosstab用于某些商品的统计,并且商品是每月不同的,有什么方法能一劳永逸而不用经常修改报告?
3#
发表于 2009-3-30 16:10:18 | 只看该作者
kkkk
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-7 03:08 , Processed in 0.092258 second(s), 26 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表