首页 > 解决方案 > 使用多个条件的 DCount

问题描述

我不确定为什么我的代码没有返回正确数量的记录。我有:

counter = DCount("*", "tbl1", "[Check] = FALSE OR DateDiff('d', [CheckDate], 
Date()) > 365 And [Room] = '" & Forms!frmSelect.txbSelect.Value & "'")
checkIndicator.Caption = "(" & counter & ")" & " available!"

似乎部分[Check] = FALSE OR DateDiff('d', [CheckDate], Date()) > 365工作正常,但整个代码不是。提前致谢!

标签: vbams-access

解决方案


您当前的代码将返回其中的记录计数tbl1

  • [Check] = FALSE(对于 的任何[Room]

或者

  • DateDiff('d', [CheckDate], Date()) > 365 [Room] = Forms!frmSelect.txbSelect.Value

根据所需的结果,我猜您需要[Room] = Forms!frmSelect.txbSelect.Value始终真,因此逻辑应按以下方式用括号括起来:

"([Check] = FALSE OR DateDiff('d', [CheckDate], Date()) > 365) And [Room] = '" & Forms!frmSelect.txbSelect.Value & "'"
 ^                                                           ^
 |                                                           |
 +----------------- Added parentheses here ------------------+

这现在返回记录的计数,tbl1其中:

  • [Room] = Forms!frmSelect.txbSelect.Value

  • [Check] = FALSE 或者 DateDiff('d', [CheckDate], Date()) > 365

推荐阅读