在日期范围内搜索 Access 查询时出现问题

Trouble with an Access Query searching within a date range

我有一个搜索保存记录并根据记录创建报告的查询。有些字段可以独立搜索,也可以与已保存记录的其他部分关联搜索(例如,可以搜索 ID、位置、and/or 是否通知警察)。但是,我 运行 在按日期搜索时遇到了问题。

我有一些字段供用户输入所需日期范围的开始日期和结束日期。当填写一个或两个字段时,搜索将提取开始日期之后、结束日期之前或所有记录的所有记录。当两个字段都被填充时,搜索将拉出一条所有字段均为空白的记录(table 中不存在)。

每个可搜索字段在查询中使用相同的条件:

Like Nz([field that you're searching],"*")

但日期范围使用了修改后的版本(抱歉,如果它超级笨拙):

Like Nz(([Data_Input_Table].[Day_Current])>=[Forms]![Search_Form]![Start_Date_Lookup_text] And ([Data_Input_Table].[Day_Current])<=[Forms]![Search_Form]![End_Date_Lookup_text],"*")

理想情况下,我希望用户按开始日期和结束日期中的一个或两个搜索。

请帮忙!

您不能在日期上使用 Like。试试这个:

[Data_Input_Table].[Day_Current] >= Nz([Forms]![Search_Form]![Start_Date_Lookup_text], [Data_Input_Table].[Day_Current]) And [Data_Input_Table].[Day_Current] <= Nz([Forms]![Search_Form]![End_Date_Lookup_text], [Data_Input_Table].[Day_Current])