eliminating the need of two equal reports

odrap

Registered User.
Local time
Today, 07:29
Joined
Dec 16, 2008
Messages
156
I have a report that can be called from a form by clicking a button. When this report after opening is closed again, the following procedure is attached to the closing event of the report takes place::


Private Sub Report_Close()
Forms!frmPrijslijsten.Visible = True
Forms!frmPrijslijsten.SetFocus
End Sub

This way i come back to the form from which the report was called.
On the same form I have a second button to save this report as PDF and in the same time creating a email with this pdf-report as attachement. ( code from a book of Helen feddema.)
Private Sub CmdPdf_Click()
On Error GoTo CreateSnapshot

Dim appOutlook As Outlook.Application
Dim msg As Outlook.MailItem

strCurrentPath = Application.CurrentProject.Path
strReport = "RprtOfferte2"
strReportFile = strCurrentPath & "\Offerte.pdf"
DoCmd.OutputTo objecttype:=acOutputReport, _
objectname:=strReport, _
outputFormat:=acFormatPDF, _
outputfile:=strReportFile

GoTo CreateEmail

CreateSnapshot:
strReportFile = strCurrentPath & "\Offerte.snp"
DoCmd.OutputTo objecttype:=acOutputReport, _
objectname:=strReport, _
outputFormat:=acFormatSNP, _
outputfile:=strReportFile

CreateEmail:
On Error GoTo ErrorHandler
Set appOutlook = GetObject(, "Outlook.Application")
Set msg = appOutlook.CreateItem(olMailItem)

With msg
.Attachments.Add strReportFile
.Subject = "Offerte" & Format(Date, "dd/mm/yyyy")
.Save
.Display
End With

DoCmd.Close acForm, Me.Name


Afsluiten:
Set appOutlook = Nothing
Exit Sub

ErrorHandler:

'Outlook is not running; open Outlook with CreateObject
If Err.Number = 429 Then
Set appOutlook = CreateObject("Outlook.Application")
Resume Next
Else
Mededeling = foutbericht("CmdPDF_Click", "frmOfferte", Err.Number)
Resume Afsluiten
End If

End Sub

When this button is clicked, the pdf report is made and saved on the place that is hardcode, but Outlook isn't opened and there's no attachement.
Therefore i'm obliged to make a second version of this report, but now without the procedure in the closing event. This way everything is running fine. However i would like to know if a solution is possible to make everything running without the need of a second version of the report.
 

Users who are viewing this thread

Back
Top Bottom