Results 1 to 6 of 6
  1. #1
    linoreale is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Oct 2014
    Posts
    10

    save report as pdf file

    Hi everyone,
    I'm not a vba expert so I need help.
    I'm using Access 2003 and I need to save a report in a pdf file to send it via email.
    On my pc is already installed pdfcreator and in its directory there is an help file modPDFCreatorAccess that contains the code above:


    Code:
    Attribute VB_Name = "modPDFCreatorAccess"
    Option Compare Database
    Option Explicit
    
    
    ' Add a reference to PDFCreator
    
    
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    
    
    Private Const maxTime = 10    ' in seconds
    Private Const sleepTime = 250 ' in milliseconds
    
    
    Public Function Start()
     PrintRep "Report1"
    End Function
    
    
    Public Sub PrintRep(RepName As String)
     Dim PDFCreator1 As PDFCreator.clsPDFCreator, DefaultPrinter As String, c As Long, _
      OutputFilename As String
     Set PDFCreator1 = New clsPDFCreator
     With PDFCreator1
      .cStart "/NoProcessingAtStartup"
      .cOption("UseAutosave") = 1
      .cOption("UseAutosaveDirectory") = 1
      .cOption("AutosaveDirectory") = "C:\"
      .cOption("AutosaveFilename") = RepName
      .cOption("AutosaveFormat") = 0                            ' 0 = PDF
      DefaultPrinter = .cDefaultPrinter
      .cDefaultPrinter = "PDFCreator"
      .cClearCache
      DoCmd.OpenReport RepName, acViewNormal
      .cPrinterStop = False
     End With
    
    
     c = 0
    
    
     Do While (PDFCreator1.cOutputFilename = "") And (c < (maxTime * 1000 / sleepTime))
      c = c + 1
      Sleep 200
     Loop
    
    
     OutputFilename = PDFCreator1.cOutputFilename
    
    
     With PDFCreator1
      .cDefaultPrinter = DefaultPrinter
      Sleep 200
      .cClose
     End With
    
    
     Sleep 2000 ' Wait until PDFCreator is removed from memory
    
    
     If OutputFilename = "" Then
      MsgBox "Creating pdf file." & vbCrLf & vbCrLf & _
       "An error is occured: Time is up!", vbExclamation + vbSystemModal
     End If
    
    
    End Sub
    In vba I've already added a reference to pdfcreator library, but I don't know exactly how to use this code.
    I tried to put it in a module then, on click event of a button, I put "call PrintRep", but the result was an error.
    Can you help please to understand how to do?


    I tried the Leban's solution, but I see it doesn't work on win 7 machines and I'd rather use pdfcreator.
    Thank you very much for help.
    Regards.

    Remigio

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If that's all you put, you didn't include the name of the report. The call should look like their example above:

    PrintRep "Report1"

    Where Report1 is the name of the report you want output.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    linoreale is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Oct 2014
    Posts
    10
    Quote Originally Posted by pbaldy View Post
    If that's all you put, you didn't include the name of the report. The call should look like their example above:

    PrintRep "Report1"

    Where Report1 is the name of the report you want output.
    Where should I have to put this?
    Could you please correct the code and re-port it?
    Thanks

    Remigio

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Behind a button is fine, you just need to pass the name of a report.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    linoreale is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Oct 2014
    Posts
    10
    Quote Originally Posted by pbaldy View Post
    Behind a button is fine, you just need to pass the name of a report.
    Tried:

    Call PrintRep "myreport"

    and compiler send a syntax error on this row

    Bye

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Did you try without Call as I suggested?

    Quote Originally Posted by pbaldy View Post
    PrintRep "myreport"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Save a Report to a PDF file. Access 2007
    By casinc815 in forum Reports
    Replies: 4
    Last Post: 06-20-2014, 10:38 AM
  2. Export report as RTF but save file name as .doc
    By Ruegen in forum Programming
    Replies: 3
    Last Post: 06-06-2014, 03:16 AM
  3. Replies: 28
    Last Post: 05-25-2014, 04:01 PM
  4. Save a report file without preview
    By alex__ice in forum Reports
    Replies: 2
    Last Post: 04-16-2013, 08:13 AM
  5. Replies: 1
    Last Post: 06-09-2011, 11:10 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