Office中国论坛/Access中国论坛

标题: 关于日期查询的问题? [打印本页]

作者: snryga    时间: 2019-6-1 22:24
标题: 关于日期查询的问题?
子窗体中“交付日期”最大是2019年9月30日,查询时在窗体上录入2019年9月30日即正常,如录入时间为2019年10月1日以后,查询结果就为0。这时为什么呢?需要怎么改代码呢?谢谢各位大侠!!!

Private Sub 查询_Click()
Dim strSQL As String
    Dim strWhere As String
    Dim ctl As Control
    Dim varI As Variant
    strSQL = "select * from 合并表 where True "
    If Me.名称.ItemsSelected.Count > 0 Then
        Set ctl = Me.名称
        strWhere = ""
        For Each varI In ctl.ItemsSelected
            strWhere = strWhere & "'" & ctl.Column(0, varI) & "',"
        Next
        strSQL = strSQL & " And 名称 in (" & Left(strWhere, Len(strWhere) - 1) & ")  "
    End If
        If Me.状态.ItemsSelected.Count > 0 Then
        Set ctl = Me.状态
        strWhere = ""
        For Each varI In ctl.ItemsSelected
            strWhere = strWhere & "'" & ctl.Column(0, varI) & "',"
        Next
        strSQL = strSQL & " And 状态 in (" & Left(strWhere, Len(strWhere) - 1) & ")  "
    End If
   
    strSQL = strSQL & IIf(IsNull(Me.站点名称), "", " and [C铁塔站名] like'*" & Me.站点名称 & "*'")
   
    strSQL = strSQL & IIf(IsNull(Me.日期开始), "", " and [交付日期]>=#" & Me.日期开始 & "#")
    strSQL = strSQL & IIf(IsNull(Me.日期截止), "", " and [交付日期]<=#" & Me.日期截止 & "#")
        
  
    Debug.Print strSQL
    Me.CRMPMS报表子窗体.Form.RecordSource = strSQL
        
End Sub
作者: snryga    时间: 2019-6-1 22:30
该代码是将列表框和文本框合在一起执行查询,主要是需要通过列表框来实现多选查询条件。
作者: tmtony    时间: 2019-6-2 00:06
要看看 这里打印的内容 是什么?
Debug.Print strSQL
是否因为没有考虑到 时间 的判断。只判断了日期,没有考虑到时间?
作者: Henry D. Sy    时间: 2019-6-3 15:55
例子呢




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