Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Okay now we are getting somewhere. Thanks for showing me that.




    This works:
    Code:
    DoCmd.OpenReport "QuoteMain", acViewPreview
    DoCmd.OutputTo acOutputReport, "", acFormatPDF, ""

    This Doesnt:
    Code:
    DoCmd.OpenReport "QuoteMain", acViewPreview
    DoCmd.OutputTo acOutputReport, "test", acFormatPDF, ""
    When the "output to" window opens it does write in "test.pdf" so i still cant see why this is an error.

    At least i know where the error is now and ill try to manipulate it to work.

  2. #17
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Thanks for the help. Ill mark as solved.

    I'm able to save it to a location, Ill have a play with the variables to get the file name and it should be good to go.

  3. #18
    roaftech is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Nov 2012
    Location
    Romania
    Posts
    65
    For the benefit of anyone researching this in the future, this is the code that I use for printing to .pdf in Access 2003:
    Code:
    Private Sub PrintPDF_Click()
    On Error GoTo Err_PrintPDF_Click
    
        Dim stRptName1 As String
        Dim stRptName2 As String
        Dim stPDF As String
        Call Filename   'Filename is a sub that calculates the filename (FileRef) based on data within the report
        
        stRptName1 = strRptName
        stRptName2 = Replace(Me.FileRef, ".pdf", "")
        stPDF = "C:\Program Files\PDFCreator\PDFCreator.exe /PF " & Chr(34) _
            & stRptName2 & Chr(34)
        
        'base report caption property must be blank
        
        DoCmd.CopyObject , stRptName2, acReport, stRptName1
        DoCmd.OpenReport stRptName2, acNormal
        DoCmd.OpenReport strRptName, acViewPreview
        DoCmd.DeleteObject acReport, stRptName2
        
    Exit_PrintPDF_Click:
        Exit Sub
    
    Err_PrintPDF_Click:
        MsgBox Err.Description
        Resume Exit_PrintPDF_Click
        
    End Sub
    In essence, the sub creates a duplicate report using the calculated filename, opens that to print (PDFcreator) then restores the original report and deletes the copy. PDFcreator pauses so that I can choose the appropriate destination directory in which to save the file.
    Note: I use an older version of PDFcreator - newer versions can add a watermark.

    EDIT: I should have mentioned that PDFCreator is set as my default printer for Windows applications.
    Last edited by roaftech; 02-03-2017 at 06:15 AM. Reason: additional info

  4. #19
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Nice work around. Given the number of suggestions which indicate a bug in converting reports to PDF files, this should be a popular thread.

  5. #20
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 8 Access 2013
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Quote Originally Posted by andy49 View Post
    Nice work around. Given the number of suggestions which indicate a bug in converting reports to PDF files, this should be a popular thread.
    This is not an issue (bug) with saving to a PDF in 2007/2010/2013/2016 when properly coded.

    This current issueis the the code id not using the correct parameters.


    In 2007 and later it really does take one line of VBA code to save a report to a PDF. No other software to install or printer driver are required.

  6. #21
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    What is that line of code? I'm using 2010..

  7. #22
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 8 Access 2013
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    You posted this does not work:

    Code:
    DoCmd.OpenReport "QuoteMain", acViewPreview
    DoCmd.OutputTo acOutputReport, "test", acFormatPDF, ""
    On Line 2 the second parameter is the name of the report to print. You have "test" not "QuoteMain".

    If you are trying to save the report named "QuoteMain" to a PDF that was previously opened in Preview mode on Line 1 then you would use something like:

    Code:
    DoCmd.OpenReport "QuoteMain", acViewPreview
    DoCmd.OutputTo acOutputReport, "QuoteMain", acFormatPDF

  8. #23
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    I've seen other examples where they use variables in that space to define the name of the report. That's probably why there so much confusion.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Report Error
    By drunkenneo in forum Programming
    Replies: 2
    Last Post: 09-17-2013, 06:29 PM
  2. Error With Hyperlink In Report
    By Aaron5714 in forum Access
    Replies: 2
    Last Post: 08-02-2012, 11:42 AM
  3. Query OK Report Error
    By endri81 in forum Queries
    Replies: 1
    Last Post: 03-10-2012, 03:30 PM
  4. #Name? Error in Report
    By kristyspdx in forum Reports
    Replies: 4
    Last Post: 12-01-2011, 11:11 AM
  5. Report error
    By indira in forum Reports
    Replies: 2
    Last Post: 03-12-2011, 03:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums