Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

email a report 1

Status
Not open for further replies.

mullet01

Technical User
Feb 7, 2003
2
0
0
GB
i set up scheduler to run a report overnight, is there a way to automatically email the report when it has finished running.
 
Either use CognosScript in which you invoke a emailobject or use Noticecast

jack
 
Mullet01,

try this macro, change the path to the correct report and change the emailaddress to an existing one.
You can change the report format to any other report type in this case it is pdf format

Good Luck!

Christenhusz


' macro to run an Impromptu report
' save the reports in pdf format with the date appended to the report name
' create an email in Outlook with the pdf attached

' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Declare Sub SaveThePDF(cat$, imr$, userclass$, pdf$ )
Declare Sub Outlook(strSubject$, strTo$, strBody$, strAttachment$)

Dim objImpRep as Object
Dim objImpApp as Object
Dim objPDFPub as Object

Dim objOutlook as Object
Dim objOutlookEmail as Object
Dim objOutlookAttachments as Object


' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Sub Main()

Dim strToday As String
Dim strReportName1 As String
Dim strCatalogName1 As String
Dim strUserClass As String
Dim strFileName1 As String
Dim strTo1 As String

strToday = date$
strCatalogName1 = "D:\program files\Cognos\cer1\samples\Impromptu\reports\Great Outdoors Sales Data.CAT"
strReportName1 = "D:\program files\Cognos\cer1\samples\Impromptu\reports\All Country Sales.imr"
strUserClass = "Creator"
strFileName1 = "D:\program files\Cognos\cer1\samples\Impromptu\reports\All Country Sales" & strToday & ".pdf"
strTo1 = "whoever@company.com"

call SaveThePDF ( strCatalogName1, strReportName1, strUserClass, strFileName1 )

msgbox "The pdf report has been generated!"

strSubject = "All Country Sales Report"
strBody = "Please find attached your pdf report. If you have any questions, please do not hesitate to contact me." & Chr(13) & Chr(13) & "John Doe" & Chr(13) & "Impromptu Report Administrator" & Chr(13) & "1-800-123-4567" & Chr(13) & Chr(13)

call Outlook(strSubject, strTo1, strBody, strFileName1)

msgbox "The email messages has been created in Outlook!"

End Sub

' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Sub SaveThePDF(cat$, imr$, userclass$, pdf$)

Set objImpApp = CreateObject("CognosImpromptu.Application")
Set objImpRep = objImpApp.OpenReport(imr)

objImpApp.OpenCatalog cat, userclass
strReportName = objImpRep.FullName
objImpRep.RetrieveAll

Set objPDFPub = objImpRep.PublishPDF

objPDFPub.Publish pdf
objImpRep.CloseReport
objImpApp.CloseCatalog
objImpApp.Quit

Set objImpApp = Nothing
Set objImpRep = Nothing
Set objPDFPub = Nothing

End Sub

' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Sub Outlook(strSubject$, strTo$, strBody$, strAttachment$)


Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookEmail = objOutlook.CreateItem(OlMailItem)
objOutlookEmail.Subject = strSubject
objOutlookEmail.Body = strBody
objOutlookEmail.To = strTo
Set objOutlookAttachments = objOutlookEmail.Attachments
objOutlookAttachments.Add strAttachment

objOutlookEmail.Save
objOutlookEmail.Send

' the following two options might be useful, but have been commented out for this example

'objOutlookEmail.Display


Set objOutlook = Nothing
Set objOutlookEmail = Nothing
Set objOutlookAttachments = Nothing

End Sub

'Note: This macro be written so that it sends it to various people by performing the following action.

'Change the strTo1 to include several email addresses:
'strTo1="fredsmith@a.com;fredsmith@b.com;fredsmith@c.com"
 
You can use the new product Notice CAST to do it !!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top