Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing the query behind an Access Report

Status
Not open for further replies.

tbiceps

IS-IT--Management
Nov 23, 2005
106
US
I have created a report based on a specific query, and it works very well. I would like to use the same report for a different form, but I need to change the query that's driving the report. I have searched all over the report's page, checked properties, etc. but not luck. Is it possible, or do I need to build a new report. By the way, I created this report using the Wizard tool.
 
The source for the report is the Record Source option on the property sheet of the report. So through code, you can just set the Record Source to different queries.
Or you could something I did. I have a popup form that requests a date range and then an Option Group with the various types of reports. There's also an Option Group to see the report in preview or directly print it. A command button then has on its OnClick event the following:
Note RptFrame is the name of the Option Group and WClause is where you build your filter for the report. You then use the DoCmd to run the report.

Private Sub Command9_Click()
Dim WClause, RName
Dim holdsort As String

Select Case [RptFrame]
Case 1
WClause = "[DateOfLease] Between #" & _
Me![Start] & "# AND #" & _
Me![End] & "#"
RName = "Sales_And_Leasing_Rpt"

Case 2
WClause = "[FinalSettlementDate]is null"
RName = "Sales_AND_Leasing_Rpt"

Case 3
WClause = "[FinalSettlementDate] Between #" & _
Me![Start] & "# AND #" & _
Me![End] & "#"
RName = "Sales_Report"
Case 4
WClause = "[FinalSettlementDate] Between #" & _
Me![Start] & "# AND #" & _
Me![End] & "#"
RName = "Sales_Report_Monthly"
Case 5
WClause = "[ReviewedDate] Between #" & _
Me![Start] & "# AND #" & _
Me![End] & "#"
RName = "Reag_Review_Date_Count_Rpt"
End Select

DoCmd.OpenReport _
ReportName:=RName, _
WhereCondition:=WClause, _
view:=Me![OutputTo]

End Sub
 
Thank you very much, both of you! Excellent feedback.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top