我有一個包含用於用戶輸入的兩個文本框的表單。兩個文本框都將「屬性」格式設置爲「短日期」。一個是「開始日期」,另一個是「結束日期」。我也有幾個表,每個表都有一個DateTime字段(「studystartdatetime」)。我希望能夠查詢這些表,但將結果限制爲DateTime字段在輸入日期(含)之間的行。目前,該條件是:Access 2007:查詢兩個短日期值之間的日期時間字段
WHERE s.studystartdatetime BETWEEN forms!frmMain!txtstartdate AND forms!frmmain!txtenddate
然而,這不返回發生指定的結束日期的行。
我已經試過CDATE,格式,則DateValue的每一個組合,我能想到的,其中用於包裝一個或所有這些領域,但我總是收到相同的神祕的錯誤:
The expression is typed incorrectly, or it is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables.
一些例子的條件我曾嘗試:
WHERE CDate(Format(s.studystartdatetime, "yyyy/mm/dd")) BETWEEN forms!frmMain!txtstartdate AND forms!frmmain!txtenddate
WHERE DateValue(Format(s.studystartdatetime, "yyyy/mm/dd")) BETWEEN forms!frmMain!txtstartdate AND forms!frmmain!txtenddate
WHERE CDate(Format(s.studystartdatetime, "yyyy/mm/dd")) BETWEEN CDate(Format(forms!frmMain!txtstartdate, "yyyy/mm/dd")) AND CDate(Format(forms!frmmain!txtenddate, "yyyy/mm/dd"))
WHERE DateValue(Format(s.studystartdatetime, "yyyy/mm/dd")) BETWEEN CDate(Format(forms!frmMain!txtstartdate, "yyyy/mm/dd")) AND CDate(Format(forms!frmmain!txtenddate, "yyyy/mm/dd"))
WHERE DateValue(Format(s.studystartdatetime, "Short Date")) BETWEEN forms!frmMain!txtstartdate AND forms!frmmain!txtenddate
等等
任何輸入到這將不勝感激:)
我曾考慮過這樣做,但出於某種原因,只是認爲不可能添加到這樣的日期值。無論如何,謝謝! – Richard 2009-10-07 17:33:16