在Access中将日期条件从表单传递到查询

时间:2015-06-17 19:44:57

标签: ms-access ms-access-2010

这应该很简单,但它不起作用,我知道我之前已经完成了。

我在表单上有一个日期字段:

enter image description here

属性设置为日期字段的ShortDate:

enter image description here

我在后端有一些代码,以确保它始终设置为该月的最后一天:

Me.txtReportDate.SetFocus
Me.txtReportDate.Text = DateAdd("d", -1, DateSerial(Year(Forms!frmRunQueries.txtReportDate), Month(Forms!frmRunQueries.txtReportDate) + 1, 1))
Me.Refresh

在查询中,我将其中一个日期设置为等于表单上的日期: enter image description here

如果我将其设置为:

=#5/31/15#

我得到数据。如果我留下它的字段参考,我没有。关于我可能做错的任何想法?

1 个答案:

答案 0 :(得分:0)

你不应该使用Text而是使用Value:

Me!txtReportDate.SetFocus
Me!txtReportDate.Value = DateSerial(Year(Forms!frmRunQueries!txtReportDate), Month(Forms!frmRunQueries!txtReportDate) + 1, 0)
Me.Refresh

此外,在您的查询中,请指定参数:Forms!frmRunQueries!txtReportDate作为日期/时间

相关问题