Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Trying to programmatically convert an Access 2007 report to pdf

Trying to programmatically convert an Access 2007 report to pdf

Trying to programmatically convert an Access 2007 report to pdf

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.

RE: Trying to programmatically convert an Access 2007 report to pdf

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.


Private Sub cboAction_Click()
'Perform action selected by user
    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"
                stExportPath = selectFolder()
                stExportFileName = stExportPath & "\" & stFileName & ".pdf"
                If Dir(stExportFileName) = "" Then
                    DoCmd.OutputTo acOutputReport, "rptVendorMeFirst", "PDFFormat(*.pdf)", stExportFileName, ShowPdf, "", 0, acExportQualityPrint
                    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 

RE: Trying to programmatically convert an Access 2007 report to pdf

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close