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


 


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
nomar2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shahid ThaikaSole ProprietorCommented:
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.
http://www.experts-exchange.com/Databases/MS_Access/Q_20654181.htm
0
jimbobmcgeeCommented:
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.

HTH

J.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.