How to load records into a subform using stored procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lin100
    New Member
    • Mar 2008
    • 2

    How to load records into a subform using stored procedure

    Access 2003. SQL 2000 Server

    The procedure Activate_Stored _Procedure_To_O btain_Rows_For_ Combo
    load all of the record in the four combo boxes correctly.

    When I select one of the combo boxes, the procedure
    Activate_Stored _Procedure_To_O btain_Rows_For_ Subform crashed at
    the code Me.Selector_Sub _Form.Form.Reco rdSource = SQL_Subform

    Run-Time error 8145
    P1 is not a parameter for procedure Obtain_Records_ For_Subform_Sel ector.

    The YELLOW HIGLIGHT IS at the code
    Me.Selector_Sub _Form.Form.Reco rdSource = SQL_Subform

    ////////////////////////////

    Code:
    Private Sub Form_Load()
    Me.Dept = Null
    Me.so = Null
    Me.Sectionno = Null
    Me.Item = Null
    
    Me.Dept.RowSource = "Exec [get_Dept_ID]"
    Me.Selector_Sub_Form.Form.RecordSource =
    "Exec [Obtain_Records_For_Subform_Selector]"
    End Sub
    
    //////////////////////////////////
    
    Private Sub Dept_AfterUpdate()
    Call Activate_Stored_Procedure_To_Obtain_Rows_For_Combo
    End Sub
    
    Private Sub SO_AfterUpdate()
    Call Activate_Stored_Procedure_To_Obtain_Rows_For_Combo
    End Sub
    
    Private Sub Item_AfterUpdate()
    Call Activate_Stored_Procedure_To_Obtain_Rows_For_Combo
    End Sub
    
    Private Sub Sectionno_AfterUpdate()
    Call Activate_Stored_Procedure_To_Obtain_Rows_For_Combo
    End Sub
    
    /////////////////////////////
    
    This procedure does work.
    
    Private Sub Activate_Stored_Procedure_To_Obtain_Rows_For_Combo()
    
    Dim SQL_Department As String
    Dim SQL_SO As String
    Dim SQL_Item As String
    Dim SQL_Section As String
    Dim strStep As String
    
    SQL_Department = "Exec [Get_Department_1] "
    SQL_SO = "Exec [Get_SO_Number_1] "
    SQL_Section = "Exec [Get_Section_Number_1] "
    SQL_Item = "Exec [Get_Item_Number_1] "
    strStep = ""
    
    If Not IsNull(Me.Dept) Then 'Department
    'SQL_From_Date = SQL_From_Date & strStep & " @From_Date = " & "'" & Me.From_Date & "'"
    'SQL_To_Date = SQL_To_Date & strStep & " @To_Date = " & "'" & Me.To_Date & "'"
    
    SQL_Department = SQL_Department & strStep & " @Department = " & "'" & Me.Dept & "'"
    SQL_SO = SQL_SO & strStep & " @Department = " & "'" & Me.Dept & "'"
    SQL_Item = SQL_Item & strStep & " @Department = " & "'" & Me.Dept & "'"
    SQL_Section = SQL_Section & strStep & " @Department = " & "'" & Me.Dept & "'"
    strStep = ","
    End If
    
    If Not IsNull(Me.so) Then 'SO_Number
    SQL_Department = SQL_Department & strStep & " @SO_Number = " & "'" & Me.so & "'"
    SQL_SO = SQL_SO & strStep & " @SO_Number = " & "'" & Me.so & "'"
    SQL_Item = SQL_Item & strStep & " @SO_Number = " & "'" & Me.so & "'"
    SQL_Section = SQL_Section & strStep & " @SO_Number = " & "'" & Me.so & "'"
    strStep = ","
    End If
    
    If Not IsNull(Me.Item) Then 'Item_Number
    SQL_Department = SQL_Department & strStep & " @Item_Number = " & "'" & Me.Item & "'"
    SQL_SO = SQL_SO & strStep & " @Item_Number = " & "'" & Me.Item & "'"
    SQL_Item = SQL_Item & strStep & " @Item_Number = " & "'" & Me.Item & "'"
    SQL_Section = SQL_Section & strStep & " @Item_Number = " & "'" & Me.Item & "'"
    strStep = ","
    End If
    
    If Not IsNull(Me.Sectionno) Then 'Section_Number
    SQL_Department = SQL_Department & strStep & " " & " @Section_Number = " & "'" & Me.Sectionno & "'"
    SQL_SO = SQL_SO & strStep & " @Section_Number = " & "'" & Me.Sectionno & "'"
    SQL_Item = SQL_Item & strStep & " @Section_Number = " & "'" & Me.Sectionno & "'"
    SQL_Section = SQL_Section & strStep & " @Section_Number = " & "'" & Me.Sectionno & "'"
    strStep = ","
    End If
    
    Me.Dept.RowSource = SQL_Department
    Me.so.RowSource = SQL_SO
    Me.Item.RowSource = SQL_Item
    Me.Sectionno.RowSource = SQL_Section
    
    Call Activate_Stored_Procedure_To_Obtain_Rows_For_Subform
    End Sub
    
    /////////////////
    
    This procedure causes a crash.
    
    Private Sub Activate_Stored_Procedure_To_Obtain_Rows_For_Subform()
    Dim SQL_Subform As String
    Dim strStep As String
    
    SQL_Subform = "Exec [Obtain_Records_For_Subform_Selector]"
    strStep = ""
    
    If Not IsNull(Me.Dept) Then 'Department
    SQL_Subform = SQL_Subform & " @Department = " & "'" & Me.Dept & "'"
    strStep = ","
    End If
    
    If Not IsNull(Me.so) Then 'SO_Number
    SQL_Subform = SQL_Subform & strStep & " @SO_Number = " & "'" & Me.so & "'"
    strStep = ","
    End If
    
    If Not IsNull(Me.Item) Then 'Item_Number
    SQL_Subform = SQL_Subform & strStep & " @Item_Number = " & "'" & Me.Item & "'"
    strStep = ","
    End If
    
    If Not IsNull(Me.Sectionno) Then 'Section_Number
    SQL_Subform = SQL_Subform & strStep & " @Section_Number = " & "'" & Me.Sectionno & "'"
    strStep = ","
    End If
    
    Me.Selector_Sub_Form.Form.RecordSource = SQL_Subform
    
    End Sub
Working...