UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Save Report To Pdf, Access 2010    
 
   
Brandi
post Feb 3 2018, 01:16 PM
Post#1



Posts: 1,659
Joined: 24-June 04



Is there a way to create a button to Save To PDF?
My user would like to automatically save a report as a pdf vs. first seeing Print Preview and then selecting Save As PDF from the Print Preview ribbon?
Thank you.
Brandi
Go to the top of the page
 
GroverParkGeorge
post Feb 3 2018, 01:48 PM
Post#2


UA Admin
Posts: 32,778
Joined: 20-June 02
From: Newcastle, WA


THis function does that.
CODE
Public Function CreateReport(ByVal intViewType As Integer) As Boolean
    Dim strDocName As String
    Dim strInvoiceName As String
    Dim strOutPutFile As String
    Dim lngReportID As Long
  

    CreateReport = False

    lngReportID = Nz(Me.lstReport, 0)
    Call RefreshReportSources(lngReportID:=lngReportID)
    lngInvoiceID = Nz(Me.cboCustomerInvoice.Column(0), 0)
    lngCustomerID = Nz(Me.cboClient, 0)
    strDocName = Nz(Me!lstReport.Column(2), vbNullString)
    strInvoiceName = Nz(Me.cboCustomerInvoice.Column(1), Nz(Me.cboMailingLabel.Column(1), "NoInvoice"))

    If Len(strDocName & vbNullString) > 0 Then
        If Me!lstReport.Column(3) = "Date Range" And (Not IsDate(Me!txtDateFrom) Or Not IsDate(Me!txtDateTo)) Then
            MsgBox prompt:="For Date related reports, you must enter a valid Date in both Date fields.", _
                Buttons:=VBOkOnly, Title:= " Missing One or Both Date Filters"
            Me!txtDateFrom.SetFocus
            GoTo CleanUp
        End If
        If intViewType = 1 Then
            strOutPutFile = "\\Gpconsultingl\GroverPark\NewInvoices\" & strInvoiceName & ".pdf"
            DoCmd.OutputTo ObjectType:=acOutputReport, objectName:=strDocName, outputformat:=acFormatPDF, _
                outputfile:=strOutPutFile, OutPutQuality:=acExportQualityPrint
            Call OpenAnyFile(FileToOpen:=strOutPutFile)
        Else
            DoCmd.OpenReport reportname:=strDocName, View:=intViewType, OpenArgs:="", Windowmode:=acDialog
        End If
    Else
        MsgBox prompt:="You must first select a report to print or preview", Buttons:=vbOkOnly, _
            Title:=" No Report Selected"
    End If
    CreateReport = True

    

End Function


The relevant line is here:

DoCmd.OutputTo ObjectType:=acOutputReport, objectName:=strDocName, outputformat:=acFormatPDF, outputfile:=strOutPutFile, OutPutQuality:=acExportQualityPrint


--------------------
Go to the top of the page
 
GroverParkGeorge
post Feb 3 2018, 01:51 PM
Post#3


UA Admin
Posts: 32,778
Joined: 20-June 02
From: Newcastle, WA


Note that this is not exactly what you described. There are four buttons on the form for which I use this.

One opens a report in Print Preview.
One sends a report to the default printer.
One sends a report to PDF and opens the PDF
One sends the recordsource of a report to Excel.

To send a report opened in Print Preview to a PDF, you could modify the ribbon, adding a new custom button to it. That custom button could call this procedure, or one similar.

--------------------
Go to the top of the page
 
Brandi
post Feb 3 2018, 06:17 PM
Post#4



Posts: 1,659
Joined: 24-June 04



Thank you. I will give this a try tomorrow and let you know if I get it to work.
Brandi
Go to the top of the page
 
Brandi
post Feb 5 2018, 05:26 PM
Post#5



Posts: 1,659
Joined: 24-June 04



I think I have this working. I just used the one line DoCmd.OutputTo ObjectType:=acOutputReport, objectName:=strDocName, outputformat:=acFormatPDF, outputfile:=strOutPutFile, OutPutQuality:=acExportQualityPrint
in the onClick event of a button along with defining strDocName and it seems to do what I need.

Thank you.
Brandi
Go to the top of the page
 
GroverParkGeorge
post Feb 6 2018, 08:03 AM
Post#6


UA Admin
Posts: 32,778
Joined: 20-June 02
From: Newcastle, WA


Excellent. We're glad to hear you solved the problem.

Continued success with the project.

--------------------
Go to the top of the page
 
Brandi
post Feb 6 2018, 02:23 PM
Post#7



Posts: 1,659
Joined: 24-June 04



When a user clicks a button to Save as PDF, the following code executes.

DoCmd.OutputTo ObjectType:=acOutputReport, objectName:=strDocName, outputformat:=acFormatPDF, outputfile:=strOutPutFile, OutPutQuality:=acExportQualityPrint


If I select the Cancel button froom the Save AS dialog, I get and Output To error and debug highlights the line above.

Is there anything that can be added to the line above to not cause an error when someone presses Cancel?

Thank you.
Brandi
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    18th June 2018 - 10:51 AM