Office中国论坛/Access中国论坛

标题: 关于筛选时间区间的语句? [打印本页]

作者: wonderfeng    时间: 2006-9-14 22:37
标题: 关于筛选时间区间的语句?
Dim strWhere As String
Dim sdate As Date
strWhere = ""
If Not IsNull(Me.month) Then
strWhere = strWhere & "([month] like '*" & Me.Month & "*') AND "----这里想用交易日期来筛选 例如:[trx_dt] in 起始日期 to 结束日期 . 起始日期和结束日期为文本框。用语句是怎么来表示的,试了半天都没试出来!
End If
If Not IsNull(Me.Trx_type) Then
strWhere = strWhere & "([trx_type] like '*" & Left(Me.Trx_type, 1) & "*') and "
End If
If Not IsNull(Me.wx_no) Then
strWhere = strWhere & "([wx_no] like '*" & Me.wx_no & "*') and "
End If
If Not IsNull(Me.Vend_no) Then
strWhere = strWhere & "([vend_no] like '*" & Me.Vend_no & "*') and "
End If

   If Len(strWhere) > 0 Then
        strWhere = Left(strWhere, Len(strWhere) - 5)
    End If
Me.交易明细_子窗体.Form.Filter = strWhere
Me.交易明细_子窗体.Form.FilterOn = True

[此贴子已经被作者于2006-9-14 14:38:42编辑过]


作者: andymark    时间: 2006-9-14 22:59
trx_dt>=#" & CDate(起始日期 ) & "#" and trx_dt<= #" & CDate(结束日期) & "#"
作者: wonderfeng    时间: 2006-9-15 05:34
我刚才试了下,在 第三个 “#”的地方报错!

By the way,学Access也有会了,唯一让人困惑的就是Access的格式真麻烦!特别是(‘’-单引号,“”-双引号,&&-与,还有表的引用,真是麻烦啊,有没有总结性的帖子啊?)
作者: andymark    时间: 2006-9-15 05:52
我自已用的好好的,你把完整的贴上来
作者: wonderfeng    时间: 2006-9-15 06:06
strWhere = ""
If Not IsNull(Me.Beg_dt) Then
strWhere = strWhere & "([trx_dt]>= #" & CDate( me.Beg_dt ) & "#" and [trx_dt]>= #" & CDate( me.Beg_dt  ) & "#" ) AND "
End If

这么写对么?我这上传不方便,将就着给我诊一下吧……
作者: andymark    时间: 2006-9-15 06:37
strWhere = strWhere & "([trx_dt] >= #" & CDate(Me.起始日期) & "#) and ([trx_dt] <= #" & CDate(Me.结束日期) & "#) AND "
作者: 一点通    时间: 2006-9-15 06:37
以下是引用wonderfeng在2006-9-14 22:06:00的发言:


strWhere = ""
If Not IsNull(Me.Beg_dt) Then
strWhere = strWhere & "([trx_dt]>= #" & CDate( me.Beg_dt ) & "#" and [trx_dt]>= #" & CDate( me.Beg_dt  ) & "#" ) AND "
End If

这么写对么?我这上传不方便,将就着给我诊一下吧……

有什么不方便的?将例子简化一下就行了,你不会程序还没有做好就登记了重要资料吧
作者: wonderfeng    时间: 2006-9-15 16:48
以下是引用一点通在2006-9-14 22:37:00的发言:



有什么不方便的?将例子简化一下就行了,你不会程序还没有做好就登记了重要资料吧



昨天晚上是在家里的,家里Access用不起来了,故不方便

谢谢Andymark!

对了,关于格式的总结帖有么?




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