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

Use Current Filter Value as Basis for a Report

Status
Not open for further replies.

gallas

Technical User
Feb 5, 2002
55
GB
I've been fiddling with this one for some time. We have a form showing company details which users apply a filter by form to find the records they require. From this form we would like to output all the filtered records to a report. Is there a way to open a report based on the current filter value?

Thanks in advance.

"If a job's worth doing, it's worth doing twice!"
 
Two answers:

First, have you tried printing from the form? If you press the Print button (or choose File | Print from the menu) on a form, the form will print for all records in the current recordset. If the recordset is filtered, it will only print the filtered records.

Second, you can try adding VBA coding to the form to open a report, setting that report's filter to the form's filter:

DoCmd.OpenReport ("ReportName",Where:=Me.Filter)

This will use the current form's (Me) filter as the WHERE clause when opening a report.

[shadeshappy] Cruising the Information Superhighway
(your mileage may vary)
 
Hi Wemeier, Thanks for yr reply.
Have cmd buttons that do the same as the print button ie print record in focus or acSelection.

Have tried the OpenReport code as follows:

Dim stDocName As String

stDocName = "rptCompaniesViewTest"
DoCmd.OpenReport stDocName, acViewPreview, , Me.Filter

It will work fine if the Filter received from the form is something like this:
((Companies.CompanyName="A.E. Smith & Son Ltd."))

But if there are lookups involved it will fail with parameter questions. eg if this is received-
((Lookup_PrimaryIndustryCode.Industry="Fruit Juices"))

Will probably need to adopt a different approach (more tedious for the user) and base the report on a query and get the criteria from a dialog box that the user will need to fill to duplicate what he has filtered on the form.

Unless anyone has any other ideas.

GW.

"If a job's worth doing, it's worth doing twice!"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top