I have a button in my form which creates and open a pdf document of my report, already filtered and sorted, but it gives an error if you attempt to create another pdf with the previous one still open. the error message is:
"The OutputTo action was canceled."
If the open pdf is closed, then the command runs fine. My Question:
How can i modify my code to check if the pdf file is already open and close it, or pops a message box advising the user to close the open pdf before running the command again? here is my code for creating a pdf document from a report in my access Form.
Private Sub CmdPreviewReport_Click()
Dim stDocName As String
stDocName = "Request_Report" ' Name of Report
strLinkCriteria = Me.MainWorkloadQueryForm.form.Filter
'Opening and Previewing filtered Report
DoCmd.OpenReport stDocName, acViewPreview, , strLinkCriteria, acHidden, Me.MainWorkloadQueryForm.form.OrderBy
DoCmd.SelectObject acReport, stDocName
'Obtaining Data from filtered report and converting report to PDF using DoCmd.OutputTo
DoCmd.OutputTo acOutputReport, "Request_Report", acFormatPDF, "Request_Report.pdf", True
'Closes the Report in Access leaving just the opened PDF
DoCmd.Close acReport, stDocName, acSaveNo