我需要知道特定部门有多少人休假,因此可以“批准”或“拒绝”新的假期请求
表 This is the Table_Add_Holidays
部门数据 Test Data with 2 departments
批准的数据 Just sample Data
我使用查询执行此查询,然后在其他地方更改了其他代码后,查询停止了。因此,我使用上面的代码从头开始,但是这并没有达到我的预期。
我想先按“已批准”过滤数据 我想按“部门”进行筛选,这样我就可以得到该部门有多少人的记录了
任何帮助将不胜感激 TIA
' Dim rstQuery As DAO.Recordset
' Dim rstQuery2 As DAO.Recordset
Dim rstQuery As DAO.Recordset2
Dim rstQuery2 As DAO.Recordset2
On Error GoTo ErrorHandler
' I was using a Query but when I tried "Set rstQuery = rstQuery2.OpenRecordset" I had a mis match
' rstQuery - was RecordSet
' rstQuery2 - whilst this was was RecordSet2
'
' Set rstQuery2 = CurrentDb.OpenRecordset("SELECT * FROM [Query_Table_Add_Holidays_CountOff_General]")
Set rstQuery2 = CurrentDb.OpenRecordset("SELECT * FROM [Table_Add_Holidays]")
rstQuery2.Filter = "StatusOfRequest = 'Approved'"
FindRecordCount = rstQuery2.RecordCount
rstQuery2.Filter = "Department = '" & oDept & "'"
FindRecordCount = rstQuery2.RecordCount
' Set rstQuery = rstQuery2.OpenRecordset
Set rstQuery = rstQuery2
If rstQuery.EOF Then
FindRecordCount = 0
Else
rstQuery.MoveLast
FindRecordCount = rstQuery.RecordCount
End If
rstQuery.Close
Set rstQuery = Nothing
答案 0 :(得分:0)
您可以 DCount :
HolidayCount = DCount("*", "[Table_Add_Holidays]", "StatusOfRequest = 'Approved' And Department = '" & oDept & "'")