Create a .pdf and attach it to an email with a click of button in vb

Posted on 2004-11-04
Medium Priority
Last Modified: 2010-05-02


I have report(s) created in Access that need to be converted to a .pdf and then need to be sent out as an attachment in an email .

I want to do this with a click of a button in a VBA.

Any suggestions or sample code would be much help.

The only thing I have so far is this...
'pdfwrite.PDFWrite (strreportname,path,link)

Basically I need under the button code to...

' Make PDF
 ' Email pdf
Question by:nomar2

Expert Comment

by:Shahid Thaika
ID: 12494341
You may need two sub-routines, one to to create the PDF file and another to mail it as an attachment.
Please see this thread. It has links to things that might get you solving your problem.
LVL 16

Accepted Solution

jimbobmcgee earned 2000 total points
ID: 12504874
If you have an existing library to write to PDF (you mention pdfwrite.PDFWrite(...)), then this should be easy.  Otherwise, you could install CutePDF (http://www.cutepdf.com) and print the document to this driver.

Creating a mail is easy (I'm assuming that, with Access, you also have Outlook)

    Sub CreateMailWithAttachment(strTo as String, strSubject as String, strBody as String, _
                                                  strAttachPath As String, blnAutoSend as Boolean)

        Dim oOutlook, oMail

        Set oOutlook = CreateObject("Outlook.Application")
        Set oMail = oOutlook.CreateItem 0

        With oMail
           .Recipients.Add strTo
           .Subject = strSubject
           .Body = strBody
           .Attachments.Add strAttachPath
        End With

        If blnAutoSend = True Then oMail.Send Else oMail.Display

    End Sub

Now call it, in your program, with

    CreateMailWithAttachment("someone@somewhere.com", "Your report", _
                                           "This is your report", "x:\mypath\mypdffile.pdf", True)

to send it automatically or

    CreateMailWithAttachment("someone@somewhere.com", "Your report", _
                                           "This is your report", "x:\mypath\mypdffile.pdf", False)

to display it on screen.




Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question