R
rwr
I'm trying to use the logic Allen Browne pointed me to, to
create a query to generate mtd and ytd totals.
I keep getting the "Run-time error 3265 item not found in
this collection" on the "Set qry = dbs.QueryDefs(tmpSQLString)".
I can't figure out what is wrong.
Dim dbs As DAO.Database
Dim rs As DAO.Recordset
Dim qry As DAO.QueryDef
Dim tmpSQLString As String
Set dbs = CurrentDb
tmpSQLString = "SELECT [tblObservationMaster].[Observer],"
tmpSQLString = tmpSQLString &
"Year([tblObservationMaster].[ObservationDate]) AS TheYear, "
tmpSQLString = tmpSQLString &
"Month([tblObservationMaster].[ObservationDate]) AS TheMonth, "
tmpSQLString = tmpSQLString & " Count([tblObservationMaster].[Observer])
AS MonthCount "
tmpSQLString = tmpSQLString & " (Select Count(A.Observer) AS YTD, "
tmpSQLString = tmpSQLString & " FROM tblObservationMaster AS A INNER
JOIN tblObservationMaster ON [A].[Observer] =
[tblObservationMaster].[Observer], "
tmpSQLString = tmpSQLString & " Where [A].[ObservationDate] >=
DateSerial(Year([tblObservationMaster].[TheYear]), 1, 1), "
tmpSQLString = tmpSQLString & " And [A].[ObservationDate] <
DateSerial(Year([tblObservationMaster].[TheMonth]), "
tmpSQLString = tmpSQLString & "
Month([tblObservationMaster].[ObeservationDate])-1,1)) AS YTDCount "
tmpSQLString = tmpSQLString & " FROM tblObservationMaster INNER JOIN A
ON [tblObservationMaster].[Observer]=[A].[Observer] "
tmpSQLString = tmpSQLString & " GROUP BY
Year([tblObservationMaster].[TheYear]),
Month([tblObservationMaster].[TheMonth]);"
Set qry = dbs.QueryDefs(tmpSQLString)
Set rs = qry.OpenRecordset()
dbs.Execute = "SELECT * INTO tblYTDTemp FROM rs;"
What I'm trying to do is take the tblObservationMaster table and
calculate MTD and YTD totals by Each Observer.
Thanks for any help you may provide.
Ron
create a query to generate mtd and ytd totals.
I keep getting the "Run-time error 3265 item not found in
this collection" on the "Set qry = dbs.QueryDefs(tmpSQLString)".
I can't figure out what is wrong.
Dim dbs As DAO.Database
Dim rs As DAO.Recordset
Dim qry As DAO.QueryDef
Dim tmpSQLString As String
Set dbs = CurrentDb
tmpSQLString = "SELECT [tblObservationMaster].[Observer],"
tmpSQLString = tmpSQLString &
"Year([tblObservationMaster].[ObservationDate]) AS TheYear, "
tmpSQLString = tmpSQLString &
"Month([tblObservationMaster].[ObservationDate]) AS TheMonth, "
tmpSQLString = tmpSQLString & " Count([tblObservationMaster].[Observer])
AS MonthCount "
tmpSQLString = tmpSQLString & " (Select Count(A.Observer) AS YTD, "
tmpSQLString = tmpSQLString & " FROM tblObservationMaster AS A INNER
JOIN tblObservationMaster ON [A].[Observer] =
[tblObservationMaster].[Observer], "
tmpSQLString = tmpSQLString & " Where [A].[ObservationDate] >=
DateSerial(Year([tblObservationMaster].[TheYear]), 1, 1), "
tmpSQLString = tmpSQLString & " And [A].[ObservationDate] <
DateSerial(Year([tblObservationMaster].[TheMonth]), "
tmpSQLString = tmpSQLString & "
Month([tblObservationMaster].[ObeservationDate])-1,1)) AS YTDCount "
tmpSQLString = tmpSQLString & " FROM tblObservationMaster INNER JOIN A
ON [tblObservationMaster].[Observer]=[A].[Observer] "
tmpSQLString = tmpSQLString & " GROUP BY
Year([tblObservationMaster].[TheYear]),
Month([tblObservationMaster].[TheMonth]);"
Set qry = dbs.QueryDefs(tmpSQLString)
Set rs = qry.OpenRecordset()
dbs.Execute = "SELECT * INTO tblYTDTemp FROM rs;"
What I'm trying to do is take the tblObservationMaster table and
calculate MTD and YTD totals by Each Observer.
Thanks for any help you may provide.
Ron