Link to home
Start Free TrialLog in
Avatar of Larry Rungren
Larry RungrenFlag for United States of America

asked on

VB6 and CR 9 Emailing a .rpt

Is it possible to run a crystal report using the crviewer in vb (already done) and email a copy of the report without having to export as a PDF first?
Avatar of Brook Braswell
Brook Braswell
Flag of United States of America image

Without exporting to "something" I would say not you can not email a report simply from what is viewed on the screen.  If you already know how to make the pdf, that would be the best way to go.  You do not have to have the users interaction to do so.  If you have a button on screen, you could make the PDF and send the email in the background as long as you have a recipient and a sender address.
Avatar of Larry Rungren

ASKER

That sounds great, do you know where I could grab sample code?
I use a tool called CodeStone to send emails with.

Public MySMTP As New SMTPClient
              Public MyPop3 As New POP3Client

              With New_Report
                   ' SHOULD YOU REQUIRE A PARAMETER FOR YOUR REPORT
                   .ParameterFields(1).AddCurrentValue Str(YOUR PARAMETER)
                   .ExportOptions.PDFExportAllPages = True
                   .ExportOptions.DestinationType = crEDTDiskFile
                   .ExportOptions.DiskFileName = "YourFilePath\" & sYourFileName & ".pdf"
                   .ExportOptions.FormatType = crEFTPortableDocFormat
                   .DisplayProgressDialog = False
                   .Export False
              End With

              Dim MyMsg As New CSMAILLib.MESSAGE

              MyMsg.Subject = sSubject
              MyMsg.To(1) = sRecipient
              MyMsg.From(1) = sSender
              ' SHOULD YOU HAVE CC OR BCC IN YOUR MAIL
              MyMsg.CC(1) = sCC  
              MyMsg.bCC(1) = sBCC
              Dim sSection As CSMAILLib.Section
              MyMsg.Sections(1).Body = Trim(sBody)
              Set sSection = MyMsg.Sections.Add
              sSection.AttachBodyFromFile ("YourFilePath\" & sYourFileName & ".pdf")
              ' for some exchange servers the user and pass are not required
              MySMTP.ConnectESMTP sSMTPServer, "", "", "", sSMTPPort  ' For Exchange 2010
              ' else use a user pass for a mail server
              MySMTP.ConnectESMTP sSMTPServer, sPOP3User, sPOP3Pass, sPop3Login, sSMTPPort
              MySMTP.SendMessage MyMsg
              MySMTP.Close

              ' when you are done it does not hurt to kill the file afterwards to keep things clean
              Kill ("YourFilePath\" & sYourFileName & ".pdf")

Open in new window

BTW - here is a link to the for the email tool
http://www.codestone.co.uk/
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the direction.. seems pretty straight forward