我希望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
当我从组合框中选择一个选项时,它会给出一个错误“参数太少。预计为1”......
我有类似的代码可以使用,因此我不确定上述原因导致错误,任何人都可以帮忙吗?
谢谢,
答案 0 :(得分:0)
像这样检查
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
代替combobox.column
COUNT(*)
并相应地调整代码以改进性能。