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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Filter (Query) to bound report

Status
Not open for further replies.

SimonTheSponge

Programmer
Feb 12, 2001
74
GB
I am completely new to access, so this is a complete newbie question

I have a report that is bound and has all of its controls bound to a query.

I would like to run this report for 2 different sets of criteria one after the other


DoCmd.OpenReport reportname 'using first criteria
DoCmd.OpenReport reportname 'using second criteria

If I pass in another query with the same fields/data structure as the query that the report is bound to will the report then use this query instead. If not how do I dynamically change the query that the report is bound to and how do I call it as such

Thanks

Simon ;-)


 
SimonTheSponge
Leave the report's record source blank, and change its record source dynamically depending upon what query is being indicated in the form that is running the report.

Put code on the report's Open event to reference the selection in the form.

If you need more help, post back.

Tom
 
Thanks Tom I'll give that a try. Will blanking the recordsource for the report not have an effect on the bound fields ?
 
You aren't really blanking the record source. What you are doing is changing the record source, depending on the query that populates the report. So there will always be a record source.

Your post suggested that that fields will be the same regardless of the criteria...just the criteria changes.

Your report's Open event will have code behind it, something such as...

Code:
If Forms!YourFormName!WhateverSuppliesTheCriteria Then
Me.RecordSource = "query1"
Else
Me.RecordSource = "query2"
End If

Give it a try and let me know.

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top