I have a database that has records at different statuses along the process, like "created", "submitted to finance", etc.
I have a form where I can choose the status from a dropdown and it will total the number of records at that status and display in an unbound field "Total".
My only problem is that when there are not any records at that status it will still display the previous statuses total. Am I missing something in my code?
Thank you ahead of time for your help!
Adam
I have a form where I can choose the status from a dropdown and it will total the number of records at that status and display in an unbound field "Total".
My only problem is that when there are not any records at that status it will still display the previous statuses total. Am I missing something in my code?
Code:
Private Sub status_AfterUpdate()
If Not IsNull(Me![status]) Then
Call CalcTotal
Else
Me![Total] = 0
End If
End Sub
Private Sub CalcTotal()
On Error GoTo Err_CalcTotal
Dim db As Database
Dim rs As Recordset
Dim Q As QueryDef
DoCmd.Hourglass True
Set db = CurrentDb()
Set Q = db.QueryDefs("qry_total")
Q.Parameters("[status]") = Me![status]
Set rs = Q.OpenRecordset()
rs.MoveFirst
Me![Total] = rs![Status Total]
Exit_CalcTotal:
DoCmd.Hourglass False
Set rs = Nothing
Set db = Nothing
Exit Sub
Err_CalcTotal:
Resume Exit_CalcTotal
End Sub
Thank you ahead of time for your help!
Adam