The cmdReorderInventoryevent procedure is listed here:
Private Sub cmdReorderInventory_Click()
This error handler skips to the CreateSnapshot section if there is an error on the line that outputs
the file to the PDF format.
On Error GoTo CreateSnapshot
strCurrentPath = Application.CurrentProject.Path
strReport = “rptProductsToReorder”
First try to export the Products to Reorder report to PDF (this will only work if you have installed
the Save to PDF utility)
strReportFile = strCurrentPath & “\Products To Reorder.pdf”
Debug.Print “Report and path: “ & strReportFile
DoCmd.OutputTo objecttype:=acOutputReport, _
objectname:=strReport, _
outputformat:=acFormatPDF, _
outputfile:=strReportFile
If the PDF file was created successfully, go to the CreateEmail section, skipping the CreateSnapshot
section of code.
GoTo CreateEmail
On Error GoTo ErrorHandler
CreateSnapshot:
Export the report to snapshot format.
strReportFile = strCurrentPath & “\Products To Reorder.snp”
Debug.Print “Report and path: “ & strReportFile
DoCmd.OutputTo objecttype:=acOutputReport, _
objectname:=strReport, _
outputformat:=acFormatSNP, _
outputfile:=strReportFile
CreateEmail:
Create an Outlook email message, fill in its subject, and attach the PDF or snapshot file to the message:
Set appOutlook = GetObject(, “Outlook.Application”)
Set msg = appOutlook.CreateItem(olMailItem)
msg.Attachments.Add strReportFile
msg.Subject = “Products to reorder for “ _
& Format(Date, “dd-mmm-yyyy”)
msg.Save
Going Beyond the Basics 12