Office中国论坛/Access中国论坛

标题: 在查询里如何写筛选年月的表达式 [打印本页]

作者: 简    时间: 2012-2-1 23:25
标题: 在查询里如何写筛选年月的表达式
我在查询里筛选年月,我这样写的:

发货年月='" & Format([发货日期],"yy-mm") & "'

我知道日期不能用字符,但用#也不对,不知该怎么写了,还请大家帮忙~~~

作者: todaynew    时间: 2012-2-2 07:04
公式本身没错。请检查等式两端的数据类型及其格式是否一致。
作者: 简    时间: 2012-2-2 07:29
我的发货日期是日期型数据,在查询中将发货年月取值为Format([发货日期],"yy-mm") ,然后我就想查询12年1月份的数据,即12-01,但不知为啥,公式是通过,但查不出结果来。
作者: andymark    时间: 2012-2-2 09:55
搞返了吧
where Format([发货日期],"yy-mm") ='12-01'
作者: todaynew    时间: 2012-2-2 11:24
简 发表于 2012-2-2 07:29
我的发货日期是日期型数据,在查询中将发货年月取值为Format([发货日期],"yy-mm") ,然后我就想查询12年1月 ...

在主窗体上建两个组合框控件,其一名曰:年度(数据源为:2010;2011;2012;2013;2014;2015,默认值为year(Date()));其二名曰:月度(数据源为1;2;3;4;5;6;7;8;9;10;11;12,默认值为month(Date()))。

筛选代码片段写:
dim strwh as string
strwh="True"
if isnull(me.年.value)=false then
  strwh=strwh & " and year(发货日期)=" & me.年.value
  if isnull(me.月.value)=false then
        strwh=strwh & " and month(发货日期)=" & me.月.value
  end if
end if
me.子窗体.form.filter=strwh
me.子窗体.form.filteron=true

同理,季度或者周的查询可比照办理。




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3