when I run this code it isn't showing the right records I need to see. I'm missing something somewhere but I'm not seeing it. The idea is for this to pull a count of all completed, in progress and Not started from the previous month and give me the totals.
Sub Update()
StatusCount "Completed"
StatusCount "In Progress"
StatusCount "Not Started"
'StatusCount "Moved to Cleanup"
'StatusCount "N/A"
'StatusCount "This is a new category" ', Now - 2, Now + 3
End Sub
Sub StatusCount(ByVal status As String, Optional start_date As Date, Optional end_date As Date)
Dim i As Variant
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim qd As DAO.QueryDef
Set db = CurrentDb
Dim SQL As String
If start_date = 0 Or end_date = 0 Then
SQL = "insert into statussummary (Count,mmyy,status) Select count(*), [created], [research status] " & _
"from [gwc master list]" & _
"where [research status] = '" & status & "'" & _
"group by [research status], [created]"
Else
SQL = "insert into statussummary (Count,mmyy,status) Select count(*), [created],[research status] " & _
"from [gwc master list]" & _
"where [research status] = '" & status & "'" & _
" and [created] > #" & start_date & "# and created < #" & end_date & "#" & _
"group by [research status], [created]"
End If
db.Execute (SQL)
rc = db.RecordsAffected
If rc = 0 Then
Debug.Print status & ": " & rc
SQL = "insert into statussummary (Count,status) values (" & rc & ", '" & status & "')"
db.Execute (SQL)
End If
End Sub
Any help is appreciated -D