Question : Opening a form with a subform produces error:

Hello,

I have a SubForm embedded in a form. When I open the form, I want to set the RecordSource property of the SubForm. I do so with this code:

Private Sub Form_Open(Cancel As Integer)
    Dim dbs As Database
   
    Set dbs = CurrentDb
    Me!subLPMSummary.Form.RecordSource = dbs.QueryDefs("qryLPMSummary").SQL
End Sub

When I open the form the code breaks at Me!subLPMSummary.Form.RecordSource and produces the error: Run-time error 2467: . The object does exist in the navigation pane and the name of the object seems to be correct. Any ideas what may be causing this error?

Dan
Code Snippet:
1:
2:
3:
4:
5:
6:
Private Sub Form_Open(Cancel As Integer)
    Dim dbs As Database
    
    Set dbs = CurrentDb
    Me!subLPMSummary.Form.RecordSource = dbs.QueryDefs("qryLPMSummary").SQL
End Sub

Answer : Opening a form with a subform produces error:

try setting the recordsource of the subform in the load event of the subform itself.
Random Solutions  
 
programming4us programming4us