Trying to print Single PDF's from a report (1 Viewer)

HoboLee

New member
Local time
Today, 15:14
Joined
Feb 11, 2019
Messages
1
Hi, i have been trying to print single PDFs from a report but all i can manage is to print the full report into multiple files, not sure what i'm doing wrong.
Can someone point me in the right direction?

this is the basic VBA code im using

Private Sub cmdSaveAsPDF_Click()



Dim qdf As DAO.QueryDef
Dim strSQL As String
Dim strPathName As String
Dim blRet As Boolean
Dim rs As Recordset
Dim stDocName As String

Dim strSavedSQL As String

If Me.Dirty Then Me.Dirty = False

stDocName = "3FolhaHorasQRT"


strSQL = "SELECT Dados.NFicha FROM Dados WHERE (((Dados.SelectedPrint)=True));"

Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)


If rs.RecordCount < 1 Then
MsgBox "Nothing found to process", vbCritical, "Error"
Exit Sub
End If

''CreateFolder CurrentProject.Path & "\TesteF"


' store the current SQL
Set qdf = CurrentDb.QueryDefs("FQR")
strSavedSQL = qdf.SQL
qdf.Close
Set qdf = Nothing


Do

Set qdf = CurrentDb.QueryDefs("FQR")
strSQL = Left(strSavedSQL, InStr(strSavedSQL, ";") - 1) & " and (Dados.NFicha = " & rs!NFicha & ");"
qdf.SQL = strSQL
qdf.Close
Set qdf = Nothing

' put in the same folder as the database
strPathName = CurrentProject.Path & "\TesteF" & rs!NFicha & ".pdf"

DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, strPathName

rs.MoveNext

Loop Until rs.EOF

rs.Close

Set rs = Nothing

' restore the SQL
Set qdf = CurrentDb.QueryDefs("FQR")
qdf.SQL = strSavedSQL
qdf.Close
Set qdf = Nothing


End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:14
Joined
Oct 29, 2018
Messages
21,358
Hi. Have you tried opening the report filtered to the record you want to save before creating the PDF? For example:
Code:
DoCmd.OpenReport "ReportName", acViewPreview, , "ID=12345"
DoCmd.OutputTo acOutputReport, "ReportName",...
DoCmd.Close acReport, "ReportName"
 

Users who are viewing this thread

Top Bottom