Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to programmatically convert an Access 2007 report to pdf

Status
Not open for further replies.

MacroScope

Programmer
Jul 17, 2010
286
US
I created an Access report that is essentially a warning letter that is to be automatically generated when certain conditions apply. I want to print a copy of the letter for snail-mailing, and I want to save a copy as a .pdf file. Of course, opening in print mode is a simple matter, so the first condition is a no brainer. What I'm trying to figure out is how I can also save a copy of the letter that was generated to a specific folder. I already have a folder, "P:\Documents\Customers\" & [CustomerID], where the document needs to be directed. I could use some help in programmatically generating and storing the file where I want it to go.

As always, any assistance will be greatly appreciated.
 
This is something I set up for user to choose how to view the report, so if you plan on having it do both automatically, the you can remove the case statements. And if you are hard coding the path, you can replace the InputBox with your path and file name. Red line shows the pdf export code.
Code:
Private Sub cboAction_Click()
'Perform action selected by user
'20151010
    Dim stFileName As String
    Dim stExportPath As String
    
    Select Case Me.cboAction
        Case "Add New Data"
            Call VendorMeFirst
            Call Form_frmUtilities.cboProcess_AfterUpdate
        Case "View Report"
            DoCmd.OpenReport "rptVendorMeFirst", acViewPreview
        Case "Save Report"
            stFileName = InputBox("Enter Name for this Summary Report." & vbCrLf & vbCrLf & _
                                  "On the next screen, choose the folder location " & _
                                  "for where you want to save the report file.", "Save Report", "VendorMeFirst_" & Me.cboTableName)
            stFileName = Replace(stFileName, "-", "_")
            If stFileName = "" Then
                MsgBox "No name was chosen, or action was cancelled by user.", vbOKOnly, "Missing File Name"
            Else
                stExportPath = selectFolder()
                stExportFileName = stExportPath & "\" & stFileName & ".pdf"
                If Dir(stExportFileName) = "" Then
                    [red]DoCmd.OutputTo acOutputReport, "rptVendorMeFirst", "PDFFormat(*.pdf)", stExportFileName, ShowPdf, "", 0, acExportQualityPrint[/red]
                Else
                    MsgBox "File " & stExportFileName & " already exists.  Please choose another name.", vbOKOnly, "File Exists"
                    Exit Sub
                End If
                MsgBox "File " & stExportFileName & " is now created", vbOKOnly, "Saved Report"
            End If
    End Select
End Sub
 
Thank you for the help.

I actually found the solution myself, and it's really just one command line.

DoCmd.OutputTo acOutputReport, "*Report Name*", acFormatPDF, "*Full File Path*" & "*Name of file*.pdf", False

Thank you again for going out of your way to find a solution. I always appreciate the assistance that people here so generously offer.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top