My error: Run-time error '91': Object variable or With block variable not set.
My code:
Expand|Select|Wrap|Line Numbers
- ######## CODE START ###########
- Dim rst As DAO.Recordset
- Dim dbs As DAO.Database
- Dim qdf As DAO.QueryDef
- Dim strResult As String
- Set qdf = dbs.QueryDefs("Report Query")
- qdf.Parameters("[Forms]![qryFormReporting]![Date_Start]") = Date_Start
- qdf.Parameters("[Forms]![qryFormReporting]![Date_End]") = Date_End
- qdf.Parameters("[Forms]![qryFormReporting]![prod_ID]") = Prod_ID
- qdf.Parameters("[Forms]![qryFormReporting]![class_ID]") = class_ID
- qdf.Parameters("[Forms]![qryFormReporting]![origin_ID]") = origin_ID
- qdf.Parameters("[Forms]![qryFormReporting]![Item_Type]") = Item_Type
- qdf.Parameters("[Forms]![qryFormReporting]![type_ID]") = type_ID
- Set dbs = CurrentDb
- sSql = "SELECT [Participation Query].*, Items_Book_HardBack_CountSold_byDate.totHard, Items_Book_SoftBack_CountSold_byDate.totSoft, Items_Book_PaperBack_Free_CountSold_byDate.*, Items_Book_PaperBack_CountSold_byDate.totPaper, Items_Book_HardBack_CountSold_byDate.[$HB], Items_Book_SoftBack_CountSold_byDate.[$SB], Items_Book_PaperBack_CountSold_byDate.[$PB], [$HB]+[$SB]+[$PB] AS sumReport, Order_Product_Revenue_Count_by_Date.sumRevenue FROM Order_Product_Revenue_Count_by_Date, Items_Book_HardBack_CountSold_byDate, Items_Book_SoftBack_CountSold_byDate, Items_Book_PaperBack_CountSold_byDate, Items_Book_PaperBack_Free_CountSold_byDate, [Participation Query];"
- Set rst = qdf.OpenRecordset(sSql)
- With rst
- .MoveFirst
- strResult = .Fields(0)
- End With
- Set rst = Nothing
- Set dbs = Nothing
- Set qdf = Nothing
- txtReport = strResult
- ######## END CODE ###########
Thank you so much for your help!