Print report based on form selection

  • Thread starter Thread starter George McDonald
  • Start date Start date
G

George McDonald

I have a form listing work completed and a yes/no field to identify records
to be printed on a report from a command button on the form.

I can find lots of articles on the code required to print a single record
but none on a selection based on multiple records.

Can anyone help me with what code would do this

Thanks
 
Hi George,

If you're wanting to open a report showing a certain set of the records
shown on the form (assuming the form and the report have the same
RecordSource), simply set the criteria you want in the Where parameter of
the OpenReport method.

For example, if your form/report have a field "WorkComplete" (boolean
datatype), you would use this to open the report showing all records for
work completed:

DoCmd.OpenReport "rptReportName", , , "WorkComplete = True"

The Where parameter must be a string containing the fieldname and the value
you want to filter by, with appropriate delimiters if necessary. It can
include a reference to a control (normally would be unbound, if you want to
use it to set the criteria for the report) on a form; eg. if you have a
textbox, txtSurname, to enter a text string to limit the report to records
for a particular Surname, your OpenReport statement would be (extra spaces
added for clarity):

DoCmd.OpenReport "rptReportName", , , "Surname = ' " & Me.txtSurname &
" ' "


HTH,

Rob
 
So your table has a yes/no field, and you want to print only those records
where this field is True (checked.)

Assuming your field is named IsPicked:
DoCmd.OpenReport, "Report1", acViewPreview, , "[IsPicked] <> False"
 
Back
Top