How do I change the recordsource of a subform at run time?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • napstar
    New Member
    • Nov 2006
    • 55

    How do I change the recordsource of a subform at run time?

    I have a subform and I'm trying to change its recordsource but i keep getting this error :
    Run-time error '2467':
    The expression you entered refers to an object that is closed or doesn't exist.

    Private Sub Combo0_AfterUpd ate()
    Dim selectName, sn, cmtxt As String
    cmtxt = Combo0.Text
    Combo0.SetFocus
    selectName = Combo0.Value

    sn = "SELECT FirstName,LastN ame FROM TrainersTable WHERE EmployeeID IN (SELECT EmployeeID FROM TrainersAndCour ses WHERE CourseID=(SELEC T CourseID FROM CoursesTable WHERE CourseName=" & "'" & cmtxt & "'" & "))"
    Form_SearchForm .RecordSource = sn

    MsgBox (Form_SearchFor m.RecordSource)


    Child8.SourceOb ject = sn

    End Sub



    Help please....
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Originally posted by napstar
    I have a subform and I'm trying to change its recordsource but i keep getting this error :
    Run-time error '2467':
    The expression you entered refers to an object that is closed or doesn't exist.

    Private Sub Combo0_AfterUpd ate()
    Dim selectName, sn, cmtxt As String
    cmtxt = Combo0.Text
    Combo0.SetFocus
    selectName = Combo0.Value

    sn = "SELECT FirstName,LastN ame FROM TrainersTable WHERE EmployeeID IN (SELECT EmployeeID FROM TrainersAndCour ses WHERE CourseID=(SELEC T CourseID FROM CoursesTable WHERE CourseName=" & "'" & cmtxt & "'" & "))"
    Form_SearchForm .RecordSource = sn

    MsgBox (Form_SearchFor m.RecordSource)


    Child8.SourceOb ject = sn

    End Sub



    Help please....
    If you are in your main form then the relative path is:
    [Code=vb]Me.SubformContr ol.Form.RecordS ource[/Code]
    The absolute path is:
    [Code=vb]Forms!MainForm! SubFormControl. Form.RecordSour ce[/Code]
    If you are in your subform then the relative path is:
    [Code=vb]Me.RecordSource[/Code]

    Please use code tags from now on.

    Comment

    Working...