Larry Rungren
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?
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.
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")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the direction.. seems pretty straight forward