Help with a command button

  • Thread starter Thread starter mnkygrl
  • Start date Start date
M

mnkygrl

Guest
I am trying to figure out a way to create a command button in a form that will print out only the related pages in a report. Any suggestions?
 
My suggestion would be to create a Command Button that opens the Report you want to print/Preview. Base the report recordset on a query that displays the records you want. Defining the parameters for this query can happen two ways. If the parameters are static, then simply have the recordsource for the report look to a saved query. If the parameters are not static, then you might want to consider creating the query at the time you open/print the Report. The only drawback with this method is you will have to make certain that the old query does not still exist prior to you creating the new one. If it does exist, then delete the old query and then create the new query.

Dim db As DAO.Database, qry As DAO.QueryDef
db.QueryDefs.Refresh
For Each qry In db.QueryDefs
If qry.Name = "QueryNameGoesHere"Then
DoCmd.DeleteObject A_QUERY, "QueryNameGoesHere"
End If
Next qry

You can then create your the query for your report immediately after you have deleted the old one (above)

Set qry = db.CreateQueryDef("QueryName", "PlaceYourSelectStatementHereCompleteWithParameters")

The above will then create the new query complete with the particular parameters or as you refer to it "only the related pages".

This should all happen using the 'OnLoad' function when your Command Button opens the Report.

After saying all this, unless the parameters of the query change dramatically, by far the simplest method is to set the Recordsource of the Report using the "OnOpen" event.

Good Luck

Pat
 
You can base your report on a stored query and set the required criteria there, or you can use the Where clause of the OpenReport method.
 

Users who are viewing this thread

Back
Top Bottom