PDA

View Full Version : [SOLVED:] Setting a subform recordset



AdrianK
05-27-2008, 03:34 AM
Hi All,

Is there a way to set the recordsource for a subform?

I have successfully used the "Forms!Form.RecordSource" successfully on normal forms, but when I am looking to set the recordsource for a subform I cannot find a control, or get this system to work.

I am using the below code:



Dim AllOpenProjects As String
' Define variable as query to be returned
AllOpenProjects = "SELECT * FROM Data WHERE ((Data.DataStatus) <> 'Completed');"
' Open form
DoCmd.OpenForm "SearchForm", acNormal, "", "", , acNormal
' Set recourdsource to the variable defined and requery
Forms!SearchSubform.RecordSource = AllOpenProjects
Forms!SearchSubform.Requery
' Close Form
DoCmd.Close acForm, "MainForm"


Where SearchForm is the form and SearchSubform is the subform it contains

However, i'm getting an error stating that the form cannot be found, however, when I open the form seperately it opens it independent of the form itself.

Is there any way to change the source of the subform itself, whilst openning it in the form?

Thanks

FrymanTCU
05-27-2008, 07:50 AM
I'm not sure but it sounds like the subform isn't properly tied to the form. You shouldn't have to query both the form and subform if the proper relationships are in place. This may be completely wrong.

AdrianK
05-27-2008, 08:05 AM
Thanks for the help, but I have just managed to solve the problem, I wasn't referring to the subform correctly, it needed to be:

Forms!SearchForm!SearchSubform.Form.RecordSource = AllOpenProjects

rather than:

Forms!SearchSubform.RecordSource = AllOpenProjects

This then sets the subform recordsource correctly.

Thanks.