Recordsource Question

D

David W

Is there a way to set the recordsource of a subreport through code?
I have got a form that I am wanting to use for setting the criteria for a
query to view a report by.
I am having problems with setting the recordsource of the subreport.

I tried: example from command button on form

Docmd.OpenReport "myreport",acPreview
Reports!myreport.mysubreport!employee.Recordsoource = "newrecordsource"

I get the response that it doesnt support this.
I dont like specifying filters because of some issues with them in reports
on different PCs.
Any Ideals?
 
M

Marshall Barton

David said:
Is there a way to set the recordsource of a subreport through code?
I have got a form that I am wanting to use for setting the criteria for a
query to view a report by.
I am having problems with setting the recordsource of the subreport.

I tried: example from command button on form

Docmd.OpenReport "myreport",acPreview
Reports!myreport.mysubreport!employee.Recordsoource = "newrecordsource"

I get the response that it doesnt support this.
I dont like specifying filters because of some issues with them in reports
on different PCs.


The place where you can reliably set a report's record
source at runtime is in the report's own Open event.

In the case of a subreport, this can only be done the first
time the subreport appears in the main report. The code to
deal with this is something like:

Sub Report_Open(...
Static Initialized As Boolean
If Not Initialized Then
Me.RecordSource = Forms!theform.newrecordsource
Initialized = True
End If
End Sub
 
D

David W

How would you check to see if a specific form is open, and if it is open,
change the recordsource? I am wanting to change the recordsource to a query
if a specific form is open, and when its not leave it set to a table.
 
M

Marshall Barton

David said:
How would you check to see if a specific form is open, and if it is open,
change the recordsource? I am wanting to change the recordsource to a query
if a specific form is open, and when its not leave it set to a table.


Here's a good way:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top