The problem you're having is that a subform is actually loaded before the
main form is loaded, thus the subform's query cannot "see" the main
form's
controls when the subform is loaded and its query is run. There are
different ways you can handle this situation.
My preferred way is to save your subform's RecordSource query as a query
in
your database (name it qryNameOfYourSubform). Then, delete the
RecordSource
from the subform (design view). Then, click a button on the main form to
"open" the subform. The code for this button would be this:
Private Sub NameOfButton_Click()
With Me.NameOfSubformControlOnMainForm.Form.
If RecordSource = "" Then
' first time the subform is being "opened", so set the
' RecordSource property for the subform
.RecordSource = "qryNameOfYourSubform"
Else
' subform has already been "opened", so just
' requery the subform's RecordSource
.Requery
End If
End With
End Sub
Please note that I've used generic names in my example
(qryNameOfYourSubform, NameOfButton, NameOfSubformControlOnMainForm), so
replace these names with the actual names that you use when you implement
this suggestion.
--
Ken Snell
<MS ACCESS MVP>
JCJ said:
Here is the subform Record Source statement:
SELECT [qtotStateAssessmentResults-grpPerformanceLevel-InCohort].*,
[qtotStateAssessmentResults-grpPerformanceLevel-InCohort].SchoolYear,
[qtotStateAssessmentResults-grpPerformanceLevel-InCohort].Subject FROM
[qtotStateAssessmentResults-grpPerformanceLevel-InCohort] WHERE
((([qtotStateAssessmentResults-grpPerformanceLevel-InCohort].SchoolYear)=Forms![frmRunQueryParam-TEST].cboVictorySchoolYear)
And
(([qtotStateAssessmentResults-grpPerformanceLevel-InCohort].Grade)=Forms![frmRunQueryParam-TEST].cboVictoryGrade)
And
(([qtotStateAssessmentResults-grpPerformanceLevel-InCohort].Subject)=Forms![frmRunQueryParam-TEST].cboSubject));
:
Post the SQL statement of the subform's RecordSource query so that we
can
better assist you.
--
Ken Snell
<MS ACCESS MVP>
Hello,
I am using a form with combo boxes in Access 2003 which runs a query
with
4
to 6 parameters, and I need to display the results of the query in a
subform.
When I add a subform in Design View and run the form, I am
immediately
prompted for the parameters before the form is displayed.
Can someone offer advice on how to link the form and subform
together,
so
that the subform is only displayed after the user clicks "Run Query"
on
the
form?
The data displayed on the subform should be dependant on the
parameters
the
user selects on the main form.
Any suggestions?