Dim rs As DAO.Recordset
Dim temptable As DAO.Recordset
Dim intMonthEntered As Integer
Dim PDcount As Long
Dim NBcount As Long
'set Project Query as rs
'set tblTempProjectCount as temptable. data is populated and deleted during code.
Set rs = CurrentDb.OpenRecordset("Count of Projects Query")
Set temptable = CurrentDb.OpenRecordset("tblTempProjectCount")
'determine the number of months of data requested. Populate temptable with a record for each month in the given range.
For intMonthEntered = 0 To DateDiff("m", Forms!frmOpenProjectCount.DateStart, Forms!frmOpenProjectCount.DateEnd)
temptable.AddNew
temptable.Fields("ProjectMonth") = DateAdd("m", intMonthEntered, Forms!frmOpenProjectCount.DateStart)
temptable.Update
Next
'Loop through temp table (which has a record for each month requested).
Do While Not temptable.EOF
PDcount = 0
NBcount = 0
rs.MoveFirst
'Loop through query that returned all product development and new business records.
Do While Not rs.EOF
'check entry data and last update or open/closed status
If rs.Fields("EntryDate") <= temptable.Fields("ProjectMonth") And (rs.Fields("MaxofDate") >= temptable.Fields("ProjectMonth") Or rs.Fields("Closed") = "False") Then
'If classified as development, add a count to Product Development tally
If rs.Fields("Status") = "Development" Then PDcount = PDcount + 1
'If classified as new business, add a count to New Business tally
If rs.Fields("Status") = "New Business" Then NBcount = NBcount + 1
End If
'grab the next project record
rs.MoveNext
Loop
'Edit the temporary table for selected month. Insert PDcount and NBcount as values in the record for month in temptable
temptable.Edit
temptable.Fields("ProdDevCount") = PDcount
temptable.Fields("NewBusCount") = NBcount
temptable.Update
'Grab the next month in temptable
temptable.MoveNext
Loop
DoCmd.OpenTable (temptable, acViewPivotChart, acEdit)