SUM Query with IF and Then Statement (1 Viewer)

chineloogbonna

Registered User.
Local time
Today, 04:08
Joined
Jul 30, 2018
Messages
65
Good Afternoon,
I am new to Access and was hoping to get some help with a query. I have a form built with a sum button. When button is clicked I want it to count all records when a match is found in the HandledType_fld.

Example: "HandledType_fld" can have Completed, Handled, NoAction etc. I'd want the query to count 5 Completed; 3 Handled and 2 NoAction.

If [HandledType_fld] = "Completed" Then
SELECT SUM(Baseload) FROM Taglines WHERE Baseload = "Baseload C";
End If

Any help you can assist with would be greatly appreciated!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:08
Joined
May 7, 2009
Messages
19,230
If you want to show the Count on an unbound textbox in the form, there is no need for a button.
Use the Form's Current event:

Private sub form_current()
On error resume next
Me.txtCompleted=dcount("1", "yourTableName","handledtype_fld='completed'")
Me.txthandked=dcount("1", "yourTableName","handledtype_fld='handled'")
Me.txtNoaction=dcount("1", "yourTableName","handledtype_fld='NoAction'")

End sub

Or in 1 line:

Me.txtStatus=dcount("1", "yourTableName","handledtype_fld='completed'") & " Completed, " & dcount("1", "yourTableName","handledtype_fld='handled'") & " Handled, " & dcount("1", "yourTableName","handledtype_fld='NoAction'") & " No Action"
 

Users who are viewing this thread

Top Bottom