K
kc-mass
Hi
I have a table that is used for reporting purposes. It will only ever have
one record and the fields of that record are filled in by a variety of
queries from a variety of tables. One field is essentially a repeating
field Month1...Month6 which need to be filled with the prior six counts of
activity levels. I am trying to assign values to those fields using a
variable reference to the field name of the record set. It is not working .
It returns an error of "Item not found in this collection".
The code is below. The line with the stars is the problem. Any help
appreciated.
Kevin
Sub FillMonthlyCounts()
Dim DB As DAO.Database
Dim RS As DAO.Recordset
Dim RSNew As DAO.Recordset
Dim strSQL As String
Dim intCounter As Integer
Dim strWhichMonth As String
Set DB = CurrentDb
Set RSNew = DB.OpenRecordset("tblReportDataByMonth")
For intCounter = 1 To 6
strSQL = "SELECT Count(tblDatesOf.DateOf) AS CountOfDateOf FROM
tblDatesOf " _
& "WHERE ((Month([DateOf])= " & PriorMonth(intCounter) & ") AND
(Year([DateOf])= " & PriorYear(intCounter) & "));"
Set RS = DB.OpenRecordset(strSQL)
If Not RS.EOF Then
RS.MoveFirst
Else
MsgBox "No data found"
Exit Sub
End If
strWhichMonth = "Month" & CStr(intCounter)
RSNew.MoveFirst
RSNew.Edit
RSNew!Fields(strWhichMonth) = RS!countofDateOf
'*********************************
RSNew.Update
Next intCounter
End Sub
I have a table that is used for reporting purposes. It will only ever have
one record and the fields of that record are filled in by a variety of
queries from a variety of tables. One field is essentially a repeating
field Month1...Month6 which need to be filled with the prior six counts of
activity levels. I am trying to assign values to those fields using a
variable reference to the field name of the record set. It is not working .
It returns an error of "Item not found in this collection".
The code is below. The line with the stars is the problem. Any help
appreciated.
Kevin
Sub FillMonthlyCounts()
Dim DB As DAO.Database
Dim RS As DAO.Recordset
Dim RSNew As DAO.Recordset
Dim strSQL As String
Dim intCounter As Integer
Dim strWhichMonth As String
Set DB = CurrentDb
Set RSNew = DB.OpenRecordset("tblReportDataByMonth")
For intCounter = 1 To 6
strSQL = "SELECT Count(tblDatesOf.DateOf) AS CountOfDateOf FROM
tblDatesOf " _
& "WHERE ((Month([DateOf])= " & PriorMonth(intCounter) & ") AND
(Year([DateOf])= " & PriorYear(intCounter) & "));"
Set RS = DB.OpenRecordset(strSQL)
If Not RS.EOF Then
RS.MoveFirst
Else
MsgBox "No data found"
Exit Sub
End If
strWhichMonth = "Month" & CStr(intCounter)
RSNew.MoveFirst
RSNew.Edit
RSNew!Fields(strWhichMonth) = RS!countofDateOf
'*********************************
RSNew.Update
Next intCounter
End Sub