Yep, Child1 is the name that you should use in the button's click event
procedure < smile >.
So, let's make these changes to the rest of the form in order to eliminate
that initial prompt and to make things work the way you want. I am assuming
here that the record source for the subform is TransactionQuery.
Open the main form in design view.
Go to the code for that button that you now have. Change its code to this:
Private FilterbyDate_Click()
If Me.Child1.Form.RecordSource = "" Then
Me.Child1.Form.RecordSource = "TransactionQuery"
Else
Me.Child1.Requery
End If
End Sub.
Then click on the subform ("Child1") in the design view. Then click on box
at top left of subform so that we can edit the subform's source object form.
Then open Properties box and select the Data tab for the Form object of the
subform. Delete TransactionQuery from the RecordSource box.
Now save the forms. Close them.
Now the forms should work the way you want. What we're doing is to have the
subform open without a recordsource, which means it won't ask you for the
dates. Then we're using the filter button to set the record source if it's
still an empty string, which requeries the subform; or else, if the
recordsource is already there, just requery the subform.
--
Ken Snell
<MS ACCESS MVP>
Richard J Cudlip said:
The name in the Subform properties is "Child1". I assume that this is the
name that the code for the button needs to refer to??
Ken Snell (MVP) said:
The prompting when you open the form initially is "my fault"... subforms
are loaded before the main form and therefore the query being used by the
subform cannot "see" the main form when the subform is being opened --
therefore you get that initial prompt. This can be avoided by a small
change
in the programming.
But before we get to that, let's nail down that you're using the correct
name for the subform in your button's code.
Open the main form in design view. Click on the very top edge of the
subform
control. Open the Properties window. Click on the Other tab. What name is
in
the Name textbox?
--
Ken Snell
<MS ACCESS MVP>
message When I open my form it immediately prompts me for 2 sets of dates.
Once I
have entered the dates the form will show the records for that range
but I
have to enter the dates twice! Entering dates in the text boxes I have
added
and using the command button has no effect at all. This is what I have
entered in the click event for the command button;
Private FilterbyDate_Click()
Me.TransactionQuery.Requery
End Sub
FilterbyDate is the command button name and TransactionQuery is the
query
that is used by the Subform. What I have done also appears to have
upset
my
total profit text box that now comes up with #Name? rather than
performing
the calculation that is previously did without any problem! For your
information, this is what I have entered into the TransactionDate field
of
my
query;
Between nz([Forms]![ProfitAnalysis]![StartDate],0) And
nz([Forms]![ProfitAnalysis]![EndDate],Date())
Can you help me get out of this tangle??
: