Go Back   Access World Forums > Microsoft Access Discussion > Reports

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 02-11-2019, 08:22 AM   #1
HoboLee
Newly Registered User
 
Join Date: Feb 2019
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
HoboLee is on a distinguished road
Trying to print Single PDF's from a report

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

HoboLee is offline   Reply With Quote
Old 02-11-2019, 08:27 AM   #2
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 855
Thanks: 7
Thanked 191 Times in 187 Posts
theDBguy will become famous soon enough
Re: Trying to print Single PDF's from a report

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"
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
Old 02-11-2019, 08:27 AM   #3
Gasman
Enthusiastic Amateur
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 3,024
Thanks: 340
Thanked 492 Times in 474 Posts
Gasman has a spectacular aura about Gasman has a spectacular aura about
Re: Trying to print Single PDF's from a report

You need the open the report with either a filter or where for each NFicha ?

https://docs.microsoft.com/en-us/off...cmd.openreport

__________________
Access novice. Sometimes trying to give something back.
Access 2007


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is online now   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
print single report pages jamesharris Reports 2 08-04-2016 12:47 PM
Print Single Report from Form Harry Taylor Modules & VBA 12 03-12-2015 03:33 AM
Print single record in report maintt Reports 22 10-06-2014 10:21 PM
Print Single Report coolcatkelso Reports 1 03-08-2009 09:56 AM
Print a single form. I don't want to use a Report. Oper3 Reports 0 01-16-2001 09:32 AM




All times are GMT -8. The time now is 05:40 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World