setting a reports RecordSource from a Form's code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hello

I have a form (frmMonthlyRegimen) with a combobox whose AfterUpdate event
sets the Form's RecordSource (called strMR_SQL). The code is fairly lengthy
and runs a bit slowly, but it works perfectly fine. Now, the command button
that is used to open this form has a line of code... DoCmd.OpenForm
("MonthlyRegimen").

I would like the button to ALSO open a report (rptMonthlyRegimen) that has
the same RecordSource as the form does. But, I don't want to waste time by
having it recalculate the record source. What is a good way to pass the
records source to the report just after the form gets it?

thanks
 
I think this will work. In design mode for the report, clear the Record
Source property. Then use the report's On Open event to set the report's
Record Source:

Me.RecordSource = Forms!MonthlyRegimen.Form.RecordSource

The form must be open before the report can open properly.
 
kingston - that worked great! So that I can learn something here, I'm
puzzled by how you used the 'Form' that appears before the '.RecordSource'.
It looks like the syntax used for subforms, but there's no subform here at
all. Any explanation? It works perfectly ... I just don't see why.
much thanks
 
I'm sorry, but I don't have a good explanation of this. Others on this forum
could definitely explain this much better than I. The only advice I can give
you is to notice how Intellisense automatically lists the properties after
the word form.
kingston - that worked great! So that I can learn something here, I'm
puzzled by how you used the 'Form' that appears before the '.RecordSource'.
It looks like the syntax used for subforms, but there's no subform here at
all. Any explanation? It works perfectly ... I just don't see why.
much thanks
I think this will work. In design mode for the report, clear the Record
Source property. Then use the report's On Open event to set the report's
[quoted text clipped - 18 lines]
 
Back
Top