Preview only current record in a report

  • Thread starter Thread starter Scott
  • Start date Start date
S

Scott

I have created a report which is a invoice for each record in my form. I
have also created a command button which will show a preview of this report
when you click it. I need to know how to make this command button preview
only the current record being viewed in the form view.

Thanks for any advice.

Scott
 
Scott said:
I have created a report which is a invoice for each record in my form. I
have also created a command button which will show a preview of this report
when you click it. I need to know how to make this command button preview
only the current record being viewed in the form view.

DoCmd.OpenReport "ReportName",,,"ID = " & Me.ID

The fourth argument of OpenReport is a WHERE clause (like in a query except
without the word "Where"). If you supply a WHERE clause that limits the
report to the record currently being viewed on the form then you get what
you want.

The example above assumes a numeric Primary Key named ID existing in both
the report and form. In your case a WHERE clause filtering on the Invoice
Number would probably be what you want. If InvoiceNum is a Text field you
would need quotes like this...

DoCmd.OpenReport "ReportName",,,"InvoiceNum= '" & Me.InvoiceNum & "'"
 
Back
Top