【发布时间】:2021-04-06 01:04:59
【问题描述】:
我希望在主页上显示一些关键数据。例如,打开不符合项 1 天、7 天超过 7 天……或者昨天应该完成但仍处于打开状态的作业计数等.等
收效甚微,我试图让记录集搜索返回基于 2 个不同条件的字段计数。然后我打算合并这两个条件......但我无法得到它工作
第一个查询试图计算日期范围从现在到 -7 天
之间的记录vSQL = "SELECT count(*) AS FieldCount FROM tblNonConformance WHERE [Date] =" & "[Date] Between #" & Format(Now(), "mm\/dd\/yyyy hh\:nn\:ss") & "# And #" & Format(Now() - 7, "mm\/dd\/yyyy hh\:nn\:ss") & "#"
第二个查询是计算仍然打开的记录数(来自数据库中的是/否字段)
vSQL = "SELECT count(*) AS FieldCount FROM tblNonConformance WHERE [NCR Clsd?]=" & False
两种情况下的字段计数都返回为空(逻辑是如果我不能让它们单独工作,我就没有希望嵌套它们)
Public Sub Tester124()
Dim vSQL As String
Dim rs As Recordset
'Creating a count SQL statement for the Date Range
vSQL = "SELECT count(*) AS FieldCount FROM tblNonConformance WHERE [Date] =" & "[Date] Between #" & Format(Now(), "mm\/dd\/yyyy hh\:nn\:ss") & "# And #" & Format(Now() - 7, "mm\/dd\/yyyy hh\:nn\:ss") & "#"
'Create a count SQL statement for the closed status
'vSQL = "SELECT count(*) AS FieldCount FROM tblNonConformance WHERE [NCR Clsd?]=" & False
'Set the recordset to variable rs and have it return the query
Set rs = CurrentDb.OpenRecordset(vSQL)
'Displaying the results.. i will do more with this when i have a usable result
With rs
MsgBox (FieldCount)
End With
End Sub
当字段计数返回为空时有什么建议吗?
【问题讨论】:
标签: sql vba ms-access recordset