views:

407

answers:

1

I'd like to be able to create, name and store individualized reports (school report cards, actually) with VB.Net and Crystal Reports using data from our SQL database.

It would be even better to be able to automatically generate individualized e-mails using e-mail addresses stored in the database, attaching the aforementioned PDF reports and sending them off.

Has anyone attempted anything like this before?

TIA for any help/pointers!

A: 

1. Create PDF programatically

Depending on the version of crystal, the export function will look similar to this

Dim objApp As CRAXDRT.Application
Dim objRpt As CRAXDRT.Report
Dim Path As String = "MyReport.rpt"

objApp = new CRAXDRT.Application
objRpt = objApp.OpenReport(Path)

With objRpt
   .ExportOptions.FormatType = crEFTPortableDocFormat
   .ExportOptions.DestinationType = crEDTDiskFile
   .ExportOptions.DiskFileName = "MyReport.PDF"
   .ExportOptions.PDFExportAllPages = True
   .Export( False )
End With

2. Send email with a PDF attachment

The "send" part will look like this:

Dim email As New MailMessage()

''//set the reply to address and the to address
email.To.Add(New MailAddress("[email protected]", "Studen Name"))
email.ReplyTo = New MailAddress("[email protected]", "Your name")


''//Assign the MailMessage's properties
email.Subject = "Your scorecard file"
email.Body = "Attached is the file you asked<br />Regards!"
email.IsBodyHtml = True

''//attach the file
email.Attachments.Add(New Attachment("c:\temp\myreport.pdf"))


Dim smtp As New SmtpClient
Try
    smtp.Send(email)
Catch ex As Exception
    messageBox("cant send")
End Try
Eduardo Molteni
Many thanks, Eduardo! I should be able to adapt this code to my situation. These are just the clues I needed.
gmillward