MS Access 2010:日期范围

时间:2018-04-26 06:42:46

标签: ms-access ms-access-2010

注意:SMonth是日期,而SYear是日期。我刚刚没有更改名称,但格式已经更改为短日期。

我在Microsoft Access Visual Basic中创建了一个代码来创建日期范围但是当我在两个文本框SMonthSYear中键入日期范围时,它只显示包含日期的记录txtYear而不是范围日期本身。这是代码。

'Date Range
ElseIf Me.SEmployeeName = "" And Me.Soo = False And Me.Scc = False And 
Me.SMonth <> "" And Me.SYear <> "" Then
Me.tbl_ALL_Query_subform.Form.RecordSource = "Select * from tbl_ALL where 
((((tbl_ALL.NTEDate ) <=  '" & Me.SMonth.Value & "') AND (tbl_ALL.NTEDate) >= 
'" & Me.SYear.Value & "')) "

1 个答案:

答案 0 :(得分:0)

你的txtTo和txtFrom似乎没有发挥作用,很难说。

但是,您将日期与文字进行比较,因此请调整查询:

ElseIf Me.SEmployeeName = "" And _
    Me.Soo = False And Me.Scc = False And _
    Me.SMonth <> "" And Me.SYear <> "" Then

    Me!tbl_ALL_Query_subform.Form.RecordSource = _
    "Select * from tbl_ALL where Month(tbl_ALL.NTEDate) <= " & Me!SMonth.Value & " AND Year(tbl_ALL.NTEDate) >= " & Me!SYear.Value & ""

如果开始日期结束日期

"Select * From tbl_ALL Where tbl_ALL.NTEDate Between #" & Format(Me!StartDate.Value, "yyyy\/mm\/dd") & "# And #" & Format(Me!EndDate.Value, "yyyy\/mm\/dd") & "#"