Emailing a Report

Arg81

Well-known member
Joined
Mar 11, 2005
Messages
949
Location
Midlands, UK
Programming Experience
1-3
I have set up a simple report that opens using Crystal Report Viewer.
Obviously from here it's possible to export the report to pdf or to print.

Here's my question / scenario.

I want to be able to email this report, as an attachment to an Outlook email. I have managed to get my application to open a new Outlook email and attach a test.doc, so that side of things is OK.
However, what I really want to do is have the app pass the parameter onto the report, have the report open and save automatically to a specified location, have the pdf file as the attachment to the email, and delete the file that was saved to disk.
The user can then send to whoever they like and add any information to the email.

Anyone have any ideas? preferably I would like the report to save as pdf, and for it to do it silently, i.e. the user doesn't see it come up on screen. Maybe I could put a splash screen with progress bar on while this happens.

cheers,
Luke
 
No one have any ideas??

Here's what I've got so far.

(btnEmail_Click)
VB.NET:
Dim oOutlook As New Outlook.Application
Dim oMailItem As Outlook.MailItem
 
oMailItem = oOutlook.CreateItem(Outlook.OlItemType.olMailItem)
With oMailItem
   .Subject = "This is the subject"
   .BodyFormat = olBodyFormat.HTML
   .Attachments.Add("c:\Temp_Docs\Report.pdf")
   .Display() 'instead of auto sending, just display email for user to edit.

So that above has got my email side of it working. Now what I want to do is the following.

Generate Report - I've got this currently that a new form opens with a parameter passing over to show the specific record for the report.
Instead of doing this, I want to silently open the report and export it as a pdf file to the c:\Temp_Docs\ folder as report.pdf

Once this has been added as an attachment to the email, I want to delete report.pdf from c:\Temp_Docs

...Any help much appriciated!
 
Resolved

Is it against the law to declare yourself a genius??? :D

I finally figured this out, and thought I'd be helpful by posting what I've done.

REQUIRED RECAP:
After entering a new record into my system and the ID generated, I want the system to create a report based on this record ID, save as a pdf file and attach to a new Outlook XP email.

The Code;

VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] mnuReport_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] mnuReport.Click
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] rpt [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] CrystalReport1
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] opt [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] CrystalDecisions.Shared.DiskFileDestinationOptions
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] oOutlook [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Outlook.Application
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] oMailitem [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Outlook.MailItem
ParamValue = lblDWRNo.Text
rpt.SetDataSource(DsSearchDWR1)
rpt.SetParameterValue("DWRNumber", ParamValue)
rpt.ExportOptions.ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat
rpt.ExportOptions.ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile
opt.DiskFileName = "c:\Temp_Docs\report.pdf"
rpt.ExportOptions.DestinationOptions = opt
rpt.Export()
MessageBox.Show("Report Exported!", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
rpt.Close()

oMailitem = oOutlook.CreateItem(Outlook.OlItemType.olMailItem)
[/SIZE][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][SIZE=2] oMailitem
[/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2].Attachments.Add("c:\Temp_Docs\report.pdf")
[/SIZE][SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] ex [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Exception
MessageBox.Show(ex.Message)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2]
.BodyFormat = OlBodyFormat.olFormatHTML
.Display()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]With
 
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][/COLOR][/SIZE] 
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE]

Now I'm working on a quick "needless" splash screen whilst the export is happening to replace the MessageBox.

Hope this is of some help to peeps.

Luke
 
V-B_New-B, i cannot understand this 3 lines code can you explain to me?

ParamValue = lblDWRNo.Text
rpt.SetDataSource(DsSearchDWR1)
rpt.SetParameterValue("DWRNumber", ParamValue)

ParamValue is use to set what?
DsSearchDWR1 is what?
 
ParamValue =

In my Crystal Report I have a parameter. When coding to open a report, you can use the above.

In my instance, I used my ID number which was shown as a label, you guessed it lblDWRNo.text


DsSearchDWR1...as shown by ds, this is MY dataset.
 
Back
Top