vba - 使用多个条件的 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
工作正常,但整个代码不是。提前致谢!
解决方案
您当前的代码将返回其中的记录计数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
推荐阅读
- python - 当约束兼容时,SciPy SLSQP 声称约束不兼容
- django - 关闭 Django 已安装包中的命令
- javascript - 从 SVG 中的 shadowRoot 元素向上遍历树
- java - java.sql.SQLDataException:ORA-01858:在更新日期时需要数字的地方发现了一个非数字字符
- c# - 已导入具有相同标识“XXX”的程序集。尝试删除重复引用之一
- javascript - 如何从 HTTPS 网站发出 HTTP 请求?
- c++ - 在另一个进程中销毁共享的 std::vector
- php - 获取上传文件的名称
- c# - 如何根据选定的参数从 XSD 文件 tableadapter 查询中填充 gridview
- android - Facebook 需要 28 个字符长的 sha1 哈希。Keytool 生成 24 个字符而不是 28 个字符