Saving Report to PDF without using DLL OCX

Discussion in 'Access VBA Modules' started by Rick Brandt, May 27, 2010.

  1. Rick Brandt

    Rick Brandt Guest

    The problem for many with Lebans' wonderful tool (which I use myself) is
    that Access 2010 is going to break it. So for many it won't survive the
    long haul.
    Rick Brandt, May 27, 2010
    1. Advertisements

  2. Rick Brandt

    Which1 Guest

    I found this code on the internet and I am trying to get it to work but I am
    As far as I can tell it seems to work fine until i get to this piece of code:

    Do While (clsPDF.cOutputFilename = "") And (i < (maxTime * 1000 / sleepTime))

    The clspdf.cOutputFilename is always empty. I also get a dialog box stating
    "This action can't be compleated because the other application is busy.
    Choose switch to to activate the busy application and correct the problem."
    But I can't select switch to because the app locks up. I have to go into
    taskmanager to end the Adobe exe process.

    I also had to comment out the handle error because the
    modPDFPrinter_PrintPDF function can't be found.

    I don't want to have to rely on dlls or ocx files.

    Any help would be appreciated
    ***** Begin Code*****
    Public Function PrinttoPDF(ByVal RptName As String, Optional
    sAutoSaveDirectory As String, Optional sAutoSaveFileName As String) As Boolean

    On Error GoTo err_Error
    Dim clsPDF As PDFCreator.clsPDFCreator 'Initialise the PDF class
    Dim strDefaultPrinter As String
    Dim strOutputFileName As String
    Dim strSaveDirectory As String
    Dim i As Long

    'set the success variable to true here but it will be set to
    'false if the function fails at any point
    PrinttoPDF = True

    Set clsPDF = New clsPDFCreator

    With clsPDF
    ..cStart "/NoProcessingAtStartup"
    ..cOption("UseAutosave") = 1 '1 = True, 0 = False

    If sAutoSaveDirectory = "" Then
    ..cOption("UseAutosaveDirectory") = 0
    ..cOption("UseAutosaveDirectory") = 1
    ..cOption("AutosaveDirectory") = sAutoSaveDirectory
    End If

    If sAutoSaveFileName = "" Then
    ..cOption("AutosaveFileName") = RptName
    ..cOption("AutosaveFileName") = sAutoSaveFileName
    End If

    ..cOption("AutosaveFormat") = 0 '0 = PDF
    strDefaultPrinter = .cDefaultPrinter
    ..cDefaultPrinter = "PDFCreator"
    Sleep 1
    DoCmd.OpenReport RptName, acViewPreview
    ..cPrinterStop = False
    End With

    i = 0

    Do While (clsPDF.cOutputFilename = "") And (i < (maxTime * 1000 / sleepTime))
    i = i + 1
    Sleep 500
    strOutputFileName = clsPDF.cOutputFilename

    With clsPDF
    ..cDefaultPrinter = strDefaultPrinter

    Sleep 200
    End With

    If strOutputFileName = "" Then
    MsgBox "Creating pdf file." & vbCrLf & vbCrLf & _
    "An error has occured: Time is up!", vbExclamation + vbSystemModal
    PrinttoPDF = False
    'Call HandleError("Report " & sAutoSaveFileName & " did not print",
    End If

    'error handler and exit
    Set clsPDF = Nothing
    Exit Function
    PrinttoPDF = False
    MsgBox Err.Description
    'Call HandleError(Err.Description, "modPDFPrinter_PrintPDF")
    Resume err_Exit

    End Function
    Which1, May 27, 2010
    1. Advertisements

  3. Do you have the free MS Office pdf addin? If so, you can just use outputto
    function, like so:

    DoCmd.OutputTo acOutputReport, "Cheese Cakes", acFormatPDF, "c:\cheesecake.
    pdf", False, "", 0, acExportQualityPrint
    WebJunkey via, May 27, 2010
  4. Rick Brandt

    Jack Leach Guest

    The problem for many with Lebans' wonderful tool (which I use myself) is
    Sometimes evolution really does suck. I'm going to go crazy when I get to
    the point where I can no longer stay with 2003.

    I wonder if 2010 will include new and ridiculous features such as the
    normalization-breaking "mulit-value fields" that came with '07 (and not to
    mention that wonderful ribbon that everyone has so much fun with!!). Way to
    go MS!!!

    Sorry, just a little rant...

    Jack Leach

    "I haven't failed, I've found ten thousand ways that don't work."
    -Thomas Edison (1847-1931)
    Jack Leach, May 28, 2010
  5. Rick Brandt

    Which1 Guest

    Is that pdf addin for Access 2003 or is only for Access 2007?
    Which1, May 30, 2010
  6. There is always the "PDF" printer.

    I use the free "Primo PDF" print driver. If you have a report that will
    print to a normal printer, then just print to the PDF "printer". It will work
    for any version of Access. Nothing to add to your Access project.
    Steve Sanford, Jun 1, 2010
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.