I am trying to call a function from a text box on a subform that returns a summed total of a single calculated field. I need to reproduce this function in multiple subforms so it is encapsulated as possible. Here's the code:
The commented out code is from trying to have the function return a variant and using "rs" as the recordset and opening rs and setting Receipts to rs.
As it is I am getting "Syntax error(missing operator) in query expression" and lists out the WHERE clause of my sql.
With it set up using rs as the recordset and returning a variant it gives me "Run-time error '91': Object variable or With block variable not set."
Thanks ahead of time for any help.
Code:
Function Receipts(ByVal CHEMICAL As String) As ADODB.Recordset Dim sql As String Dim beginningDate As Date Dim endingDate As Date Dim chemicalID As String beginningDate = DateAdd("h", 6, [Forms]![frmProduction]![txtBeginningDate]) endingDate = DateAdd("h", 30, [Forms]![frmProduction]![txtEndingDate]) chemicalID = CHEMICAL sql = "SELECT (Sum(Abs([tblReceiptScaleData]![WeightIn1]-[tblReceiptScaleData]![WeightOut2]+[tblReceiptScaleData]![WeightIn2]-[tblReceiptScaleData]![WeightOut1]))) AS OffloadQty " _ & "FROM ItemMasterList INNER JOIN (sPULINH INNER JOIN tblReceiptScaleData ON sPULINH.Pono = tblReceiptScaleData.OrderNumber) ON ItemMasterList.SAGEItemKey = sPULINH.Itemkey " _ & "WHERE (((ItemMasterList.OperationsDescription) = " & chemicalID & ") AND ((tblReceiptScaleData.TimeOut2) >= " & beginningDate & ") AND ((tblReceiptScaleData.TimeOut2) <= " & endingDate & ")); " Set Receipts = New ADODB.Recordset Receipts.Open sql, CurrentProject.Connection, , adLockOptimistic 'Receipts = rs("OffloadQty") Set Receipts = Nothing
As it is I am getting "Syntax error(missing operator) in query expression" and lists out the WHERE clause of my sql.
With it set up using rs as the recordset and returning a variant it gives me "Run-time error '91': Object variable or With block variable not set."
Thanks ahead of time for any help.
Comment