【发布时间】:2015-11-27 07:25:02
【问题描述】:
我有一个包含 7 个复选框的表单,每个复选框都是一个状态:打开、关闭、拒绝、推迟、工作、复制和测试
复选框的值可以是True或False。
现在我想在 VBA 的 SQL 语句中连接复选框的值:
Dim Status As String
If (Open.value = True) Then Status = " status = 'Open'" End If
If (Postponed.value = True) Then Status = " or status = 'Postponed'" End If
If (Closed.value = True) Then Status = " or status = 'Closed'" End If
If (Rejected.value = True) Then Status = " or status = 'Rejected'" End If
If (Working.value = True) Then Status = " or status = 'Working'" End If
If (Duplicated.value = True) Then Status = " or status = 'Duplicated'" End If
If (Testing.value = True) Then Status = " or status = 'Testing'" End If
sqlstatement = "select * from cr where " & status
上面代码的问题是它有点硬编码。这意味着如果 open.value 不正确,那么整个语句都是错误的。那么如何使其动态地仅在 where 中组合标准(可以选择或取消选择任何复选框)?
【问题讨论】:
标签: ms-access vba ms-access-2010