current record PDF issues

paul.brisenden

New member
Local time
Today, 20:06
Joined
Feb 6, 2025
Messages
17
Hi guys, need some help. as a novice to Access i had some help by a member to add a PDF save command that will only save the current record i am working on (not the usual issue that you get with saving entire report records)
I have the code (below) and it works no problem for this one form. my issue is that i now have another 2 forms that require the same feature. i have tried a basic copy and paste with wording change to reflect the new form title and report title. however i still produce an entire list of records in the report instead of the record i am working on.
Could anyone help with what i am missing here? (by the way, i am very very new to Access and have zero experience with building filters)

the below code works for the form headed NCE but i need this to work for 2 other forms too.

Thanks in advance.

1744885083292.png
 
only comment on the code.
you need to add backslash ("\") to CurrentProject.Path before appending the filename.

Code:
DoCmd.OutputTo acOutputReport, "NCE REPORT", acFormatPDF, CurrentProjectPath & "\NCE REPORT.pdf", True
 
only comment on the code.
you need to add backslash ("\") to CurrentProject.Path before appending the filename.

Code:
DoCmd.OutputTo acOutputReport, "NCE REPORT", acFormatPDF, CurrentProjectPath & "\NCE REPORT.pdf", True[/co
[/QUOTE]
Thanks for that Arnelgp, the code works fine but my issue is getting this to work on two other forms.
 
Thanks for that Arnelgp, the code works fine but my issue is getting the same function to work on two other forms.
 
You need to start understanding the code. :(
All you need to do is
Give the correct criteria for each report. Identify where that is done.
Open the correct report.
Print to the correct pdf.
Close said report.
 
no, it doesn't look fine for me.
try on Immediate window:

Code:
?CurrentProject.Path & "NCE Report.pdf"
 
then show us the result?
on my understanding with your code, the text "NCE Report.pdf" is being appended to CurrentProject.Path.
in order to save it to the Path, add a backslash ("\") to it.
 
1744888430371.png
does the same thing with both versions. sends the report to PDF and will only send the current record that i am working on. when i attempt this with other forms it send the entire list of reports found within that form. my issue is that i only wish to send the current form, to report and then to pdf. the ID is within that purple box on the form this would determine which report i wish to send to pdf.
 
Show your code. :(
We are not mindreaders.
That form looks like the criteria should be Me.EventId?
Is it?
 
And that is? :(
the outcome selects the current record that i am working on and sends it to PDF (only the current record)
the EventID is irrelevant as there are multiple events but each event has multiple NCE or EWN ID.

code is below.


Option Compare Database
Option Explicit




Private Sub Command164_Click()

DoCmd.OpenReport "ewn report", acViewPreview, , "EWNID=" & Nz(Me.EWNID, 0), acHidden
DoCmd.OutputTo acOutputReport, "EWN Report", acFormatPDF, CurrentProject.Path & "\EWN Report.pdf", True
DoCmd.Close acReport, "EWN Report"
End Sub

this code currently sends full list of reports to pdf, instead of a singular record that i am working on.
the same code works no problem for NCEID but when attempting to operate the same function within EWNID on a separate form called EWN it sends every report.
 
the outcome selects the current record that i am working on and sends it to PDF (only the current record)
the EventID is irrelevant as there are multiple events but each event has multiple NCE or EWN ID.

code is below.


Option Compare Database
Option Explicit




Private Sub Command164_Click()

DoCmd.OpenReport "ewn report", acViewPreview, , "EWNID=" & Nz(Me.EWNID, 0), acHidden
DoCmd.OutputTo acOutputReport, "EWN Report", acFormatPDF, CurrentProject.Path & "\EWN Report.pdf", True
DoCmd.Close acReport, "EWN Report"
End Sub

this code currently sends full list of reports to pdf, instead of a singular record that i am working on.
the same code works no problem for NCEID but when attempting to operate the same function within EWNID on a separate form called EWN it sends every report.
To clarify. the event code remains as 1 as this is event number one, but i may have numerous different EWNs (early warning notice) for any delay to any event (an event could be delayed for multiple reasons)
 
You need to use the CORRECT criteria for that single record, if all you want is one record.
 
Sorry Gasman, as explained before, i really am new to Access, what would my correct Criteria be? within the code above, where is the incorrect item? Thanks Gasman
 
the outcome selects the current record that i am working on and sends it to PDF (only the current record)
the EventID is irrelevant as there are multiple events but each event has multiple NCE or EWN ID.

code is below.


Option Compare Database
Option Explicit




Private Sub Command164_Click()

DoCmd.OpenReport "ewn report", acViewPreview, , "EWNID=" & Nz(Me.EWNID, 0), acHidden
DoCmd.OutputTo acOutputReport, "EWN Report", acFormatPDF, CurrentProject.Path & "\EWN Report.pdf", True
DoCmd.Close acReport, "EWN Report"
End Sub

this code currently sends full list of reports to pdf, instead of a singular record that i am working on.
the same code works no problem for NCEID but when attempting to operate the same function within EWNID on a separate form called EWN it sends every report.
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.
 
My favorite learning technique has always been. "Try it and see what happens."
 
Sorry Gasman, as explained before, i really am new to Access, what would my correct Criteria be? within the code above, where is the incorrect item? Thanks Gasman
YOU know your system, we do not.
If you want one record, you need to select whatever identifies that as a unique record.

Start walking your code and see what it produces, especially when you are new at this.
See my debugging link in my signature if you do not know how to do that.

However it all boils down to understanding what the code does :(, so take time to do that. it will save you loads of time for the future.
 
A method that has always worked for me is to change something in the record source of the report to limit the records returned. For instance if you have an employee table [tblEmployees] and want to limit the report to a specific EmpID, create a query [qselEmployees] with the SQL of
Code:
SELECT * FROM tblEmployees

Use this query as a contributor to your report record source. Then immediately before outputting your report, change the SQL of [qselEmployees] to:
Code:
strEmpSQL = "SELECT * FROM tblEmployees WHERE EmpID = " & Me.EmpID
CurrentDb.QueryDefs("qselEmployees").SQL = strEmpSQL
DoCmd.OutputTo acOutputReport, "EWN Report", acFormatPDF, CurrentProject.Path & "\EWN Report.pdf", True
'You can set your SQL back to where it was or leave it alone

There is code for changing the SQL at this page.
 

Users who are viewing this thread

Back
Top Bottom