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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report to PDF then email

Status
Not open for further replies.

Yardyy

Technical User
Aug 13, 2002
448
GB
Hi, Does anyone have any code suggestions that i can use to convert an access 2003 report to pdf then email. I have been studying the article at for the last three weeks, and cannot get my head around it.. Any help most appreciated.

Many Thanks
Yurov Ardyy
 
Well I use the PDFCreator API to convert to PDF via VBA...


This is for converting word docs, but hopefully you can use it for reports...

Code:
Function Word2PDF(sDoc As String, sPDF)

    On Error GoTo EH_Word2PDF

    Dim oPDF As PDFCreator.clsPDFCreator
    Dim DefaultPrinter As String
    Dim oWord As Word.Application
    Dim OutputFilename As String
    Dim c As Integer
    
    'Create Instances
    Set oPDF = New clsPDFCreator
    Set oWord = CreateObject("Word.Application")
    
    Word2PDF = ""
    
    'Open document
    oWord.Documents.Open sDoc
    
    With oPDF
        .CStart "/NoProcessingAtStartup"
        .cOption("UseAutosave") = 1
        .cOption("UseAutosaveDirectory") = 1
        .cOption("AutosaveDirectory") = oWord.ActiveDocument.Path
        .cOption("AutosaveFilename") = sPDF
        .cOption("AutosaveFormat") = 0
        DefaultPrinter = .cDefaultPrinter
        .cDefaultPrinter = "PDFCreator"
        oWord.PrintOut Background:=True
        .cClearCache
        .cPrinterStop = False
    End With
 
    c = 0
 
    Do While (oPDF.cOutputFilename = "") And (c < (maxTime * 1000 / sleepTime))
        c = c + 1
        Sleep 500
    Loop

    OutputFilename = oPDF.cOutputFilename
    
    With oPDF
        .cDefaultPrinter = DefaultPrinter
        Sleep 1000
        .cClose
    End With

    Sleep 2000 ' Wait until PDFCreator is removed from memory

    sPDFDoc = OutputFilename
 
    oWord.Quit False

    If OutputFilename = "" Then
        MsgBox "Creating pdf file." & vbCrLf & vbCrLf & _
        "An error has occured: Time is up!", vbExclamation + vbSystemModal
    End If

Exit_Word2PDF:
    Set oPDF = Nothing
    Set oWord = Nothing
    Exit Function

EH_Word2PDF:
    MsgBox "There was an error converting Word2PDF ->" & Error(err) & ", " & CStr(err)
    Word2PDF = "Error"
    Resume Exit_Word2PDF

End Function

The constants are defined like so
Code:
Private Const maxTime = 20    ' in seconds
Private Const sleepTime = 250 ' in milliseconds

hope it helps

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Thanks for example will try out and report back.

Many Thanks
Yurov Ardyy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top