Form to control report

  • Thread starter Thread starter mogens
  • Start date Start date
M

mogens

I have a report that I use for different purposes. What I do now is that
I have a number of different queries with varying selections, and a a
corresponding number of different reports based on the before mentioned
queries.

But as all queries have the same content (only the selections differs),
and all reports are identical (apart from referring to various queries),
this seems to be a clumpsy way to do this. Isn't it possible in Access
to start up a form with selection criteria which in turn displays the
same report?
 
mogens said:
I have a report that I use for different purposes. What I do now is that
I have a number of different queries with varying selections, and a a
corresponding number of different reports based on the before mentioned
queries.

But as all queries have the same content (only the selections differs),
and all reports are identical (apart from referring to various queries),
this seems to be a clumpsy way to do this. Isn't it possible in Access
to start up a form with selection criteria which in turn displays the
same report?


Yes, you can do that. The simple answer is to set the
report's RecordSource property in the report's Open event.
If the form stashes the query name in a (hidden?) text box,
then the report would use a line of code like:
Me.RecordSource = Forms!nameofofrm.nameottetbox

Even that is not the best way to do it if the only
difference in the queries is the criteria. In this case,
you only need one query with no selection criteria. In this
scenario, if you open the report from the database window,
it will display all the data. But, the code in the form's
buttons to open the report supplies the criteria using the
OpenReport method's WhereCondition argument. Skipping over
the step where you determine the criteria, the code would
look like:

stDoc = "nameofreport"
stWhere = "somefield = somevalue"
DoCmd.OpenReport stDoc, , , stWhere
 
Marshall said:
mogens wrote:





Yes, you can do that. The simple answer is to set the
report's RecordSource property in the report's Open event.
If the form stashes the query name in a (hidden?) text box,
then the report would use a line of code like:
Me.RecordSource = Forms!nameofofrm.nameottetbox

Even that is not the best way to do it if the only
difference in the queries is the criteria. In this case,
you only need one query with no selection criteria. In this
scenario, if you open the report from the database window,
it will display all the data. But, the code in the form's
buttons to open the report supplies the criteria using the
OpenReport method's WhereCondition argument. Skipping over
the step where you determine the criteria, the code would
look like:

stDoc = "nameofreport"
stWhere = "somefield = somevalue"
DoCmd.OpenReport stDoc, , , stWhere
You can also find a nice free report filter utility here:
http://www.mile50.com/access/rfil/index.htm

and a commercial one, Cub reporter, that costs $40 here:
https://www.swreg.org/soft_shop/224/shopscr7.shtml

Bob
 
Back
Top