Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Lin100
Yak Posting Veteran
70 Posts |
Posted - 2007-01-08 : 20:53:37
|
Access 2003 and SQL 2000 Server.I have a form that have two combo boxes (Dept, and SO) and a subform (Q_FilteringQuery subform).When I first clicked on the combo box named Dept, Access pop-up a dialog box asking me to entera value for a variable that was declared in the stored procedure (@SO_Param). This should not havehappened. next, I clicked the OK button without inputing the value for @SO_Param, and then Iselect the combo box Dept. Then an error comes upRun-Time error '8145'P1 is not a parameter for procedure sp_getsubfrm_recsThe variable P1 was never declared anywhere in the VBA code nor was it ever declared in the stored procedure.////////////////////////////////////////////////////////////Private Sub Dept_AfterUpdate()Dim strsql As StringDim iDept As IntegerIf Not IsNull(Me.Dept) TheniDept = CInt(Me.Dept)strsql = "SELECT DISTINCT [1_Job - Parent].SONumber, Ref_DepartmentID.ID"strsql = strsql & " FROM dbo.[1_Job - Parent] INNER JOIN"strsql = strsql & " dbo.Ref_DepartmentID"strsql = strsql & " ON dbo.[1_Job - Parent].Department_Name = dbo.Ref_DepartmentID.DepartmentName"strsql = strsql & " WHERE dbo.Ref_DepartmentID.ID = " & iDeptElsestrsql = "SELECT DISTINCT [1_Job - Parent].SONumber, Ref_DepartmentID.ID"strsql = strsql & " FROM dbo.[1_Job - Parent] INNER JOIN"strsql = strsql & " dbo.Ref_DepartmentID"strsql = strsql & " ON dbo.[1_Job - Parent].Department_Name = dbo.Ref_DepartmentID.DepartmentName"End IfMe.so.RowSource = strsql'call subget_subfrm_recsEnd Sub///////////////////////////////////////////////////////////////////////////Private Sub SO_AfterUpdate()Dim strsql As StringDim LgSO As LongDim iDept As IntegerIf Not IsNull(Me.Dept) TheniDept = CInt(Me.Dept)End IfIf Not IsNull((Me.so)) ThenLgSO = CLng(Me.so)strsql = "SELECT DISTINCT [1_Job - Parent].ItemNumber, Ref_DepartmentID.ID"strsql = strsql & " FROM dbo.[1_Job - Parent] INNER JOIN"strsql = strsql & " dbo.Ref_DepartmentID"strsql = strsql & " ON dbo.[1_Job - Parent].Department_Name = dbo.Ref_DepartmentID.DepartmentName"strsql = strsql & " WHERE dbo.Ref_DepartmentID.ID = " & iDeptstrsql = strsql & " AND SONumber =" & LgSOstrsql = strsql & " ORDER BY ItemNumber"Me.Item.RowSource = strsqlget_subfrm_recs 'call procedureElsestrsql = "SELECT DISTINCT ItemNumber"strsql = strsql & " FROM [1_Job - Parent] "strsql = strsql & " ORDER BY ItemNumber"Me.Item.RowSource = strsqlget_subfrm_recs 'call procedureEnd IfEnd Sub//////////////////////////////////////////////Private Sub get_subfrm_recs()On Error GoTo Err_showDim p_Ref_DepartmentID As IntegerDim p_SO As LongDim StrRS As StringStrRS = "Exec sp_get_subfrm_recs "If Not IsNull(Me.Dept) Thenp_Ref_DepartmentID = CInt(Me.Dept)End IfIf Not IsNull(Me.so) Thenp_SO = CLng(Me.so)End IfIf Not IsNull(Me.Dept) And IsNull(Me.so) ThenStrRS = StrRS & "@param1 = " & p_Ref_DepartmentID & ","ElseIf Not IsNull(Me.Dept) And Not IsNull(Me.so) ThenStrRS = StrRS & "@param1 = " & p_Ref_DepartmentID & "," & " @SO_param = " & p_SO & ","ElseIf IsNull(Me.Dept) And Not IsNull(Me.so) ThenStrRS = StrRS & " @SO_param = " & p_SO & ","End IfEnd IfEnd IfStrRS = Left(StrRS, Len(StrRS) - 1)Me.Q_FilteringQuery_subform.Form.RecordSource = StrRS <--- ERROR. YELLOW HIGHLIGHTIf Me.Q_FilteringQuery_subform.Form.RecordsetClone.RecordCount = 0 ThenMe.Q_FilteringQuery_subform.Visible = FalseElseMe.Q_FilteringQuery_subform.Visible = TrueEnd IfExit SubErr_show:MsgBox "Error: " & Err & " " & Err.DescriptionMsgBox "Error", Err.HelpFile, Err.HelpContextIf Err.Number <> 0 ThenMsg = "Error # " & Str(Err.Number) & " was generated by " _& Err.Source & Chr(13) & Err.DescriptionMsgBox Msg, , "Error", Err.HelpFile, Err.HelpContextEnd Sub///////////////////////////////////////////////CREATE PROCEDURE sp_get_subfrm_recs (@param1 Int = Null , @SO_Param Int = Null)AsSELECT DISTINCT[1_Job - Parent].Department_Name, [1_Job - Parent].SONumber, [1_Job - Parent].ItemNumber, [1_Job - Parent].SectNumber,[1_Job - Parent].RecordInitiateDate, [1_Job - Parent].MechUser,[1_Job - Parent].ElecUser, [1_Job - Parent].GreenTagUser,[1_Job - Parent].GreenTagDateFROM [1_Job - Parent] INNER JOIN Ref_DepartmentIDON [1_Job - Parent].DepartmentID = Ref_DepartmentID.IDWHERE [1_Job - Parent].DepartmentID = coalesce(@param1,[1_Job - Parent].DepartmentID)AND [1_Job - Parent].SONumber = coalesce(@SO_Param,[1_Job - Parent].SONumber)GO |
|
|
|
|
|
|