Command from Form to change Record Source of Report

  • Thread starter Thread starter orbojeff
  • Start date Start date
O

orbojeff

I'm using VB to change the SQL Record Source of my Sub Form on my Main
form.
On my main form I also have a Command Button that opens a report.
What command could I use to set the Record Source of my report,
rpt_SEARCH

Thanks
Jeff
 
Could you limit the report with the WhereCondition of OpenReport?

Example:
If your subform is limiting the records where the InvoiceDate is in the last
3 months, you could:
Dim strWhere As String
strWhere = "[InvoiceDate] >= DateAdd(""m"", -3, Date())"
DoCmd.OpenReport "Report1", acViewPreview, , strWhere
 
orbojeff said:
I'm using VB to change the SQL Record Source of my Sub Form on my Main
form.
On my main form I also have a Command Button that opens a report.
What command could I use to set the Record Source of my report,
rpt_SEARCH

Thanks
Jeff

Unless you want to open the report in design view (not a good idea), the only
place the RecordSource of a Report can be changed is with code in the Open event
of that report. It cannot be changed "from the outside" like you can with a
Form.

Your form can either pass information to the Report so the Report's code knows
what to do, or you can have the Report's code "look back" at the Form to
determine what it should do.
 
Back
Top