問題描述
MS Access 表單日期/時間輸入問題 (MS Access Forms Date/Time Entry Trouble)
所以我有幾個表,我想在它們的日期/時間字段上進行過濾。這是我正在試驗的表單控件的快照。
這份報告可能最終會在每月一次,因此過濾器“Between Forms!Sorting!OldestDate and Forms!Sorting!NewestDate” 通常會正常工作。然而,有時只在一天內運行它很有用,如圖所示,在這種情況下,我需要過濾器計算出“Between #M/D/YYYY 0:00:00# and #M/D” /YYYY 23:59:59#”。然而,在控件上設置格式以實際記錄時間和日期並沒有奏效。
我想,首先,也許時間沒有顯示,因為我的文本框是太小了,所以我嘗試添加底部文本框。快照中的顯示是我想要的,但是,如果我在文本框中單擊,日期就會消失,只顯示時間。在我進入並手動添加時間之前,它也根本不顯示任何時間。
有沒有辦法強制顯示短日期和長時間?或者有沒有辦法,比如說,將 NewestDate 的默認時間值設置為 23:59:59?
目前唯一的“解決方案”是 我可能有 CVDate(CDbl(Forms!Sorting!NewestDate)+0.99999) 在我的 WHERE 子句中出現多次,這將使事情更難跟踪或發現錯誤。
我有 vba 經驗,但我從未嘗試使用它來屏蔽/編輯傳遞給查詢的表單參數。我正在通過 MS Office Professional Plus 2019 使用 Access。
參考解法
方法 1:
First, in your query, specify as parameters:
[Forms]![Sorting]![OldestDate] DateTime,
[Forms]![Sorting]![NewestDate] DateTime;
Then you can filter on:
[YourDateField] >= [Forms]![Sorting]![OldestDate] And [YourDateField] < DateAdd("d", [Forms]![Sorting]![NewestDate])
If [YourDateField]
is text, change that to DateTime. If that is not possible (it should be), use:
DateValue([YourDateField])