current record PDF issues

I don't like Dwane's method because it temporarily changes a permanent object.

I don't know your application but ONE method is to add a hidden field to the form that opens the report. To make this work, you need to do two things.
1. Change the RecordSource query of the Report to add a where clause that references the hidden form field:

Where SomePK = Forms!myform!myPK

2. When you click on the print report button, copy the PK of the record you want to show to the hidden field.


This method is simple and works fine (also delete the OpenReport in your current code because it is not necessary and just adds unnecessary overhead) -- unless you want to open the same report from multiple forms. In that case, you can use a Tempvar instead of a form control reference.
 
With the code I suggested with the code in the link, it’s very easy to reset the SQL to the original. You can also build a fairly sophisticated where clause, apply it, and call it from any form.

Using a control on a form limits you to having that form open and setting the correct value.
 
You have two lines.

The first one opens the report for Preview on-screen. It contains a filter: "EWNID=" & Nz(Me.EWNID, 0)

The second one sends another copy of the report to PDF. This is a different copy of the report, not the one just opened for Preview on-screen. It has no filter. Add your filter to this second line that sends the other copy to PDF.
No so George.

With code
Code:
Sub PrintOneRecord()
DoCmd.OpenReport "rptPressure", acViewPreview, , "PressureID = 13", acHidden
DoCmd.OutputTo acOutputReport, "rptpressure", acFormatPDF, "f:\temp\ReportTest.pdf"
DoCmd.Close acReport, "rptpressure"
End Sub

Result
1745049015077.png
 

Users who are viewing this thread

Back
Top Bottom