Question : How to email an Access 2002 report in pdf format

It's always been very easy to seamlessly (no user intervention) email an Access 2002 report as a .snp file by simply using

DoCmd.SendObject acSendReport etc

However, I'm having problems with both Adobe Acrobat and Outlook when I try to email an Access 2002 report as a .pdf file. I'm using the following simplified test code to investigate some nagging problems, but with no success to date:

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Sub TestEmailPDFReport _
    ( _
        ByVal vstrReport As String, _
        ByVal vstrTo As String _
    )

    On Error GoTo Proc_Err
   
    Dim appOutlook      As Outlook.Application
    Dim mliMailItem     As Outlook.MailItem
   
    Dim strFQFile       As String
    Dim strPath         As String
    Dim strPDFPrinter   As String
   
    ' for testing purposes only
    strPath = "C:\Temp\"
    ' use the report name for the file name
    strFQFile = strPath & vstrReport & ".pdf"
    ' get rid of previous versions of the file
    On Error Resume Next
    Kill strFQFile
    On Error GoTo Proc_Err
    ' temporarilty change the printer to adobe
    strPDFPrinter = "Adobe PDF"
    Set Application.Printer = Application.Printers(strPDFPrinter)
    ' now we have the problem of filling in the print dialog box
    ' with the desired pdf file name so the operation is seamless to the user
    ' there must be a better way than sendkeys
    ' even with sendkeys, the {ENTER} is not taking effect - why ????
    SendKeys strFQFile & "{ENTER}"
    ' open the report and save it as a pdf file
    ' this also seems to launch the Adobe Acrobat application
    ' there must be some way to stop Acrobat from launching
    ' and keep the process seamless for the user
    DoCmd.OpenReport vstrReport, acNormal, , , acHidden
    ' reset the printer
    Set Application.Printer = Nothing
    ' for some reason the pdf file does not seem to be instantly available
    ' why ?????
    ' loop until it seems available
    Do While Dir(strFQFile) = vbNullString
        Call Sleep(100)
    Loop
    ' just because the file is now there does not been it's avaialble
    ' why ?????
    ' cause another bigger delay
    Call Sleep(1000)
    ' start outlook
    Set appOutlook = New Outlook.Application
    ' create a new email message
    Set mliMailItem = appOutlook.CreateItem(olMailItem)
    With mliMailItem
        .To = vstrTo
        .Subject = "test"
        .Body = "here's your stuff"
        .Attachments.Add strFQFile
        ' the send method causes yet another problem
        ' it generates an annoying message that an application
        ' is trying to send an email message
        ' there must be some way to avoid this message in order to make
        ' the process seamless for the user
        .Send
    End With
    ' clean up
    Set mliMailItem = Nothing
    'appOutlook.Quit
    Set appOutlook = Nothing
   
Proc_Exit:
    Exit Sub
   
Proc_Err:
    VBA.Err.Raise Err.Number, , Err.Description
End Sub

I need a seamless implementation so that no user intervention is required to email an Access 2002 report in pdf format. Any suggestions would be GREATLY appreciated.

Answer : How to email an Access 2002 report in pdf format

Hi guys.

rmk doesn't really seem to care about the disposition, but for now, we'll give it the benefit of the doubt and suppose that he didn't get a valid answer.

jadedata: I'm going to unsubscribe just in case you guys continue the discussion. You know how to reach me if you determine you'd like some different action taken here.

Thanks BOTH for your input. :)

PAQed, with points refunded (500)

amp
Community Support Cleanup Moderator
Random Solutions  
 
programming4us programming4us