Full Version: creating different versions of a report with code
UtterAccess Discussion Forums > Microsoft® Access > Access Reports
piggitypow
On a form, I have several command buttons. Each button opens a preview of a basically the same report, but for different geographic regions. For the time being, I have actually created a separate report for each region by altering the base report's query criteria slightly.

This works, but I would prefer to set the query criteria in the command button code so that only one report needs to be in the database. The report has a field CountyNumber (integer), and I want to set the CountyNumber in the command buttons such that cmdCounty1 opens the report with CountyNumber=1, cmdCounty2 opens the report with CountyNumber=2, etc.

Any tips for the proper code to load the form differentially for the various buttons?
JayNoelOlimpo
Hi;

try removing any criteria in the reports recordsource and have this on click event procedure of a command button ...

DoCmd.OpenReport "ReportNameHere", acPreview, , "[CountryNumber]=" & Me![CountryNumber]

in the from :

and you could create some sort of like a combo box to select for a country naming that control as CountryNumber ..

HTH.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.