[英]MS ACCESS Counting Records from table based on multiple criteria
I want a text box in Access to update with the number of records found where a manager has an "overdue" record in the table dependent on the manager selected in a combo box, I have the following code but am getting an error: 我希望Access中的一个文本框更新记录的数量,该数量取决于在组合框中选择的管理器中某个管理器在表中具有“过期”记录的管理器,我有以下代码,但出现错误:
Private Sub Combo26_AfterUpdate()
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT Advisor FROM tbltargets WHERE manager = '" & Me.Combo26.Column(0) & "' AND overdue = 'Overdue'")
If rs.EOF Then
Me.Text35 = 0
MsgBox "no overdue records", vbOKOnly
Else
rs.MoveLast
Me.Text35 = rs.RecordCount
rs.Close
End If
End Sub
When I select an option from the combo box it gives me an error "Too few parameters. Expected 1"... 当我从组合框中选择一个选项时,它给我一个错误“参数太少。预期为1” ...
I have similar code which works so am unsure why the above is resulting in an error, could anyone help? 我有类似的代码可以正常工作,所以不确定上面的代码为什么会导致错误,有人可以帮忙吗?
Thank you, 谢谢,
Check like this 像这样检查
Private Sub Combo26_AfterUpdate()
Dim rs As DAO.Recordset
If IsNull(Combo26.value) Then Exit Sub
Set rs = CurrentDb.OpenRecordset("SELECT COUNT(*) AS CNT FROM tbltargets WHERE manager = '" & Combo26.value & "' AND overdue = 'Overdue'")
If Not rs.BOF Then
If Nz(rs!CNT, 0) = 0 Then
Me.Text35 = 0
MsgBox "no overdue records", vbOKOnly
Else
Me.Text35 = rs!CNT
End If
End If
End Sub
combobox.value
instead of combobox.column
combobox.value
而不是combobox.column
COUNT(*)
and adapted the code accordingly to improve perfs. COUNT(*)
并相应地修改了代码以提高性能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.